How to calculate total number with multiple selected

Dear Survey Solution User!!!

Currently, our team is working on Survey Solution for data collection, and now we have some question cannot solved and looking for help. The question is what kind of animals you have raised in 2019? (Multiple selected) then I created roster has linked with this question for count number of each animal. For example : I have selected like Cow, Buffalo and Chicken and in the Roster I was linked, it appear all animals I have selected for fill in the number of these. My question, How can I calculate total number of animal?

Best regard

Marady

Do you want to count the number of animals checked in your multiple selection question?

In your example do you wish a variable that display you 3 (because selected Cow, Buffalo and Chicken)?
If your answer is yes, you only need to create a variable of type Long Integer
In the expression of your variable write this:
NameMultipleSelectedQuestion == null ? 0 : NameMultipleSelectedQuestion.Count()

1 Like

Building on @kv700032 answer,

if you want to sum up the number of animals ACROSS TYPES, assuming you have a question (nr_animal) WITHIN a roster (livestock_roster) which is sourced* from your multi-select question:

Create a variable Long Integer or Double outside of livestock_roster with expression:

livestock_roster.Sum(element=>element.nr_animal)
or
livestock_roster.Select(element=>element.nr_animal).Sum()

*You wrote linked, this word has a different meaning n Survey Solutions, see linked question here.

1 Like

Dear @kv700032

Thanks for ur answer!!!
I want to sum all the number animal that i have selected. Actually the question I have been designed Q1. What type the animal did you raise in 2019? ( this is multi selection)
Q2. How many animal did you have raised in 2019?
In question Q2 I have created Roster to link with Q1. Ex: If Chosen Cow, duck, and Chicken. It will be appeared 3 the animal I have selected to fill in the number. Ex: I have cow 2 , duck 10 and chicken 20. My question I want sum of these animal number. Thanks

Best Regard

Marady

Dear Petter_Brueck

Thanks for great answer

Best Regard

Marady


It doesn’t work

It’s very hard to read but I think you are not using the ROSTER before “.Select” but the MSC Question.

In general, you work with rosters, and the syntax I showed above is a LINQ expression which is described here.

Hey Peter_brueck !!!

Thanks for helpful
Sure, I use question before roster. Now I detail my question to you

Q1. What type animal did you raised in 2019 (Multi-selection)
Code 1=Cow, 2= Pig, 3= duck, 4= chicken and 5= other after that
I created roster Number of Livestock Roster and Roster Source I selected I multi- select question, then
I created Q2. How many animal u raised in 2019 (I setted the question type is numeric)
so, when I test
I have selected Code 1, 2, 3, 4 from Q1 and in Q2 dropped down the answer follow Q1. then
I fill in cow 2 and pig=1 and duck= 2 and chicken=5
Total 10. What I want can total number livestock equal 10?
I followed you by create variable outside from roster and but it doesn’t work
I hope have the best solution from you!!!

As written above, check the expression within the variable:

ROSTERNAME.Select(element=>element.NUMERICQUESTION).Sum()

1 Like

Thanks @peter_brueck

I working well !!!