 # Conditional Aggregate

Hello! Is there a way to take a numeric value and aggregate it into one of two lists based on a separate MC question?

I am having students submit their height in inches and selecting their favorite core class.
Is there a way to sort the heights of students who like math and the students who like English into two separate aggregate numberlists?

I’ve tried:
numberlist(“Y_1”): when core.isSelected(1) and in1.submitted aggregate(in1.numbericValue otherwise""

numberlist(“Y_2”): when core.isSelected(2) and in1.submitted aggregate(in1.numbericValue otherwise""
but it does not work. Anyone have any ideas if this is possible and/or what I am doing wrong?

Here is the activity:
Where do I stand?

You can use `when-otherwise` inside `aggregate`:

``````numberList("Y_1"): aggregate(when core.isSelected(1)
and in1.submitted in1.numericValue otherwise 0)
``````

You can’t use “” because `aggregate` won’t accept strings, so I used `0` because a student obviously won’t have `0` height.

Thank you for the help. The only problem is that I am using these lists to make boxplots and all of those 0’s will throw those graphs off. Is there a way to remove the 0’s from the list before they are made a boxplot?

There are two dotplots and two boxplots that combine all the data and 2 boxplots that separate the data based on a MC question.

Would it be easier if I linked the answer to the MC question to a separate math inputs and then combined the lists for the overall boxplot?

You could do this for each list in the graph. Just make sure you aggregate corresponding height lists conditionally in the same way as the class choice (i.e. one list based on selection 1 and a second based on selection 2).

https://www.desmos.com/calculator/frt07lfar9

Awesome!

I went and made a separate math input based on their MC choice.
numberList(“A”)=aggregate(in1.numericValue)
numberList(“B”)=aggregate(in2.numericValue)

Then in the graph:
dotplot(Y)
Y=join(A,B)

I’m testing it right now. It seems to work so far as long as both MC choices are selected.

1 Like