# Conditional Aggregate

**URL:** <https://cl.desmos.com/t/conditional-aggregate/1482>\
**Category:** Questions\
**Tags:** aggregate\
**Created:** [September 11, 2020, 8:23pm UTC](https://cl.desmos.com/t/conditional-aggregate/1482 "2020-09-11T20:23:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nnovotny87](https://avatars.discourse-cdn.com/v4/letter/n/439d5e/32.png) [@nnovotny87](https://cl.desmos.com/u/nnovotny87)\
**Post date:** [September 11, 2020, 8:23pm UTC](https://cl.desmos.com/t/conditional-aggregate/1482/1 "2020-09-11T20:23:33Z")

</div>

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?](https://teacher.desmos.com/activitybuilder/custom/5f5bca859b9bd0397daeef11)

---

<div class="post-metadata">

**Author:** ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)\
**Post date:** [September 11, 2020, 8:59pm UTC](https://cl.desmos.com/t/conditional-aggregate/1482/2 "2020-09-11T20:59:08Z")

</div>

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

```auto
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.

---

<div class="post-metadata">

**Author:** ![nnovotny87](https://avatars.discourse-cdn.com/v4/letter/n/439d5e/32.png) [@nnovotny87](https://cl.desmos.com/u/nnovotny87)\
**Post date:** [September 11, 2020, 10:06pm UTC](https://cl.desmos.com/t/conditional-aggregate/1482/3 "2020-09-11T22:06:43Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Daniel\_Grubbs](https://yyz1.discourse-cdn.com/flex031/user_avatar/cl.desmos.com/daniel_grubbs/32/719_2.png) [@Daniel\_Grubbs](https://cl.desmos.com/u/Daniel_Grubbs)\
**Post date:** [September 12, 2020, 2:53am UTC](https://cl.desmos.com/t/conditional-aggregate/1482/4 "2020-09-12T02:53:05Z")

</div>

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](https://www.desmos.com/calculator/frt07lfar9)

---

<div class="post-metadata">

**Author:** ![nnovotny87](https://avatars.discourse-cdn.com/v4/letter/n/439d5e/32.png) [@nnovotny87](https://cl.desmos.com/u/nnovotny87)\
**Post date:** [September 12, 2020, 3:07am UTC](https://cl.desmos.com/t/conditional-aggregate/1482/5 "2020-09-12T03:07:59Z")

</div>

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.

> **[Where do I stand? • Activity Builder by Desmos](https://teacher.desmos.com/activitybuilder/custom/5f5bca859b9bd0397daeef11)**
>
> Adapted from the Stats Medic lesson "Where do I stand?" Day 8: Describing Quantitative Data Day 2
