Sum values of a variable in a fixed roster based on a condition

Hi Survey Solutions Team,

I have a fixed roster that has 4 options. (Q806b_roster)
Within the roster I have a question that takes the amount spent for each category. (Q806b)
I need to make a variable that takes the sum of the first 3 options. (Exclude option 4).
Currently I have the following code in a long integer variable. Q806b_roster.Sum(x=>x.Q806b). This gives me the sum of all 4 options. I need to sum only the first 3 options.

Appreciate the help!


Try something like this:

  // filter to observations with matching row codes
  // sum up the values

Note: this is pseudo-code. I didn’t have time to test it.

Or take the sum of all (as you do it) and subtract the value of the 4th category from that sum.

Ps: if the 4th one is TOTAL perhaps that shouldn’t be entered in the first place, agree?

Thank you for this Arthur. Initially I had the same idea, just didn’t know the correct syntax.

I was able to do it successfully with your code. Thanks!


Thank you for the concern Sergiy. Your intuition about the 4th option being the Total is correct. Here, we allow them to record ‘don’t know’ for the breakdowns (first 3 options). But the total is always required. Hope this makes sense.