# Nested Count If

**URL:** <https://community.amazonquick.com/t/nested-count-if/33190>\
**Category:** Q&A\
**Tags:** parameters, calculations, Business-Intelligence-Engineer, quick-sight\
**Created:** [July 29, 2024, 7:51pm UTC](https://community.amazonquick.com/t/nested-count-if/33190 "2024-07-29T19:51:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juan](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Juan](https://community.amazonquick.com/u/Juan)\
**Post date:** [July 29, 2024, 7:51pm UTC](https://community.amazonquick.com/t/nested-count-if/33190/1 "2024-07-29T19:51:27Z")

</div>

Hello community  
I have a problem, I can’t nest aggregation functions, but I would like to be able to count the amount of users(token field in the rows) that have at least 1 record in the week(count of the id field) and also those that have no records, to be able to verify, but I can’t isar countif, ifelse doesn’t work because I can’t segment by ‘created\_at’ which is the date field in the columns, I can want to know this data by week(companies with at least 1 id record), not in the total.

 ![Captura de pantalla (281)](https://d1wl4jav5dp96l.cloudfront.net/original/3X/3/e/3e3995cacc0a46afb5e205c30f0213deaba77ee5.png)

---

<div class="post-metadata">

**Author:** ![Nico](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/nico/32/32113_2.png) [@Nico](https://community.amazonquick.com/u/Nico)\
**Post date:** [July 31, 2024, 6:28am UTC](https://community.amazonquick.com/t/nested-count-if/33190/2 "2024-07-31T06:28:45Z")

</div>

Hi @Juan ,

can you share a simple picture (eg. take a screenshot form it in Excel) from your desired outcome?

Best regards,  
Nico

---

<div class="post-metadata">

**Author:** ![Juan](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Juan](https://community.amazonquick.com/u/Juan)\
**Post date:** [July 31, 2024, 2:09pm UTC](https://community.amazonquick.com/t/nested-count-if/33190/3 "2024-07-31T14:09:01Z")

</div>

hello @Nico  
Thanks you for your reply.  
Here I show what is currently in quicksight in a pivot table, the rows where token is located, are my users, the date columns, are divided by weeks with my created\_at field, and the values, are the amount of orders(count of id).  
My ideal result, would be the total expected field, where the count of tokens(users) that have at least 1 order(count of id) would be done per week, so for the week of July 29th we have 4 tokens with at least 1 order, for the week of July 15th we have only 1 token with at least 1 order.  
Hope i made myself clear in the desired outcome, I await your answer in case you find a viable solution.

 ![Captura de pantalla (283)](https://d1wl4jav5dp96l.cloudfront.net/original/3X/1/3/13948b9cac87cde32ebeb66938a65b2ad9fc1f86.png)

---

<div class="post-metadata">

**Author:** ![Nico](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/nico/32/32113_2.png) [@Nico](https://community.amazonquick.com/u/Nico)\
**Post date:** [August 1, 2024, 6:26am UTC](https://community.amazonquick.com/t/nested-count-if/33190/4 "2024-08-01T06:26:46Z")

</div>

Hi @Juan  
Thanks for the explanation.

It seems like you need two visualizations. One for the upper part (not marked) and one for the lower one.  
I think it is not possible to do both in one pivot table.

Were you able to create the calculation for “total expected”?

Best regards,  
Nico

---

<div class="post-metadata">

**Author:** ![ali](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/ali/32/15390_2.png) [@ali](https://community.amazonquick.com/u/ali)\
**Post date:** [August 1, 2024, 7:02am UTC](https://community.amazonquick.com/t/nested-count-if/33190/5 "2024-08-01T07:02:12Z")

</div>

This is not possible to create pivot table in QS like you created in excel. But you can write calculated field and add that field in your pivot table. which eventually shows another column in table.  
you can write calculated filed like this: ifelse(count(id) \> 0 OR isNotNull(count({id})), 1 , 0)  
add this in your table and change the total from default to sum.  
 ![image](https://d1wl4jav5dp96l.cloudfront.net/original/3X/f/8/f80df63fc0ed09c5b9a28feacb706ebf45fc8dcb.png)

---

<div class="post-metadata">

**Author:** ![Juan](https://avatars.discourse-cdn.com/v4/letter/j/a698b9/32.png) [@Juan](https://community.amazonquick.com/u/Juan)\
**Post date:** [August 1, 2024, 1:16pm UTC](https://community.amazonquick.com/t/nested-count-if/33190/6 "2024-08-01T13:16:20Z")

</div>

Hey @ali that work as i expected, thanks for that solution!
