# Sum of items in one array depending on what's in another array

**URL:** <https://community.glideapps.com/t/sum-of-items-in-one-array-depending-on-whats-in-another-array/68202>\
**Category:** Ask for Help\
**Created:** [November 28, 2023, 4:16pm UTC](https://community.glideapps.com/t/sum-of-items-in-one-array-depending-on-whats-in-another-array/68202 "2023-11-28T16:16:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ninjaaa](https://avatars.discourse-cdn.com/v4/letter/n/6f9a4e/32.png) [@Ninjaaa](https://community.glideapps.com/u/Ninjaaa)\
**Post date:** [November 28, 2023, 4:16pm UTC](https://community.glideapps.com/t/sum-of-items-in-one-array-depending-on-whats-in-another-array/68202/1 "2023-11-28T16:16:57Z")

</div>

How can I create a sum of items in one array depending on what is written in another array?

My example (see screenshot): I like to make a separate sum of xp for each category.  
 → Player 1 shall have 30xp in Cooperation and 0xp in Battle and 0xp in Knowledge  
 → Player 2 shall have 0xp in Cooperation, 40xp in Battle and 40xp in Knowledge

How can I achieve that?

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/b/e/bef64a3975852f6d3cfb3de23b03aff6ca4ddf83.png)

---

<div class="post-metadata">

**Author:** ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)\
**Post date:** [November 29, 2023, 1:08am UTC](https://community.glideapps.com/t/sum-of-items-in-one-array-depending-on-whats-in-another-array/68202/2 "2023-11-29T01:08:32Z")

</div>

Assuming you have that data available, what’s your next step? Do you want to use a rollup somewhere to sum the xp for each category?

---

<div class="post-metadata">

**Author:** ![Ninjaaa](https://avatars.discourse-cdn.com/v4/letter/n/6f9a4e/32.png) [@Ninjaaa](https://community.glideapps.com/u/Ninjaaa)\
**Post date:** [November 29, 2023, 11:03am UTC](https://community.glideapps.com/t/sum-of-items-in-one-array-depending-on-whats-in-another-array/68202/3 "2023-11-29T11:03:16Z")

</div>

Exactly. I want to show a chart where the user can see how many xp in each category he has.

And some more information:

- the date in the screenshot comes from a log table
- in the log table each row contains the category of the challenge, the xp, the username of the initiator and the usernames of all participants
- all players (initiator and participants) shall receive xp

Here’s a screenshot from the log table:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/3/e/3e9a055b3a20437ab56ed394d798f47995c3b2ac.png)

Column 1: category  
Column 2: email initiator  
Column 3: emails of all other participants  
Column 4: points that those people receive for doing the challenge

---

<div class="post-metadata">

**Author:** ![Jeff\_Hager](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/jeff_hager/32/43_2.png) [@Jeff\_Hager](https://community.glideapps.com/u/Jeff_Hager)\
**Post date:** [November 29, 2023, 2:41pm UTC](https://community.glideapps.com/t/sum-of-items-in-one-array-depending-on-whats-in-another-array/68202/4 "2023-11-29T14:41:56Z")

</div>

Wouldn’t it be better to create separate relations or queries specific to each category? Then you could add a Rollup for each category to sum the total.
