# Nesting of aggregate functions is not allowed

**URL:** <https://community.amazonquick.com/t/nesting-of-aggregate-functions-is-not-allowed/12302>\
**Category:** Q&A\
**Tags:** error, calculations, quick-sight\
**Created:** [April 16, 2023, 8:07pm UTC](https://community.amazonquick.com/t/nesting-of-aggregate-functions-is-not-allowed/12302 "2023-04-16T20:07:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![olgetta](https://avatars.discourse-cdn.com/v4/letter/o/eada6e/32.png) [@olgetta](https://community.amazonquick.com/u/olgetta)\
**Post date:** [April 16, 2023, 8:07pm UTC](https://community.amazonquick.com/t/nesting-of-aggregate-functions-is-not-allowed/12302/1 "2023-04-16T20:07:49Z")

</div>

I need to apply the following formula in case job\_id=${Job1}:

2 \* sqrt({WSL\_calculated\_job\_1} \* (1-{WSL\_calculated\_job\_1})/sum({number\_workers})) \* 100

Im doing it by:  
avg(ifelse(job\_id=${Job1},(2 \* sqrt({WSL\_calculated\_job\_1} \* (1 - {WSL\_calculated\_job\_1})/sum({number\_workers})) \* 100), NULL))

where _WSL\_calculated\_job\_1_ is another calculated field:  
avg(ifelse({job\_id}=${Job1}, {WSL}, NULL))

Im getting nesting of aggregate functions is not allowed when creating calculated field.  
Is there a way I can modify the calculated field to make it work?  
Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Max](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/max/32/2288_2.png) [@Max](https://community.amazonquick.com/u/Max)\
**Post date:** [April 17, 2023, 2:14pm UTC](https://community.amazonquick.com/t/nesting-of-aggregate-functions-is-not-allowed/12302/2 "2023-04-17T14:14:28Z")

</div>

> [@olgetta](#):
>
> avg(ifelse({job\_id}=${Job1}, {WSL}, NULL))

try making this an avgOver with a pre\_agg

> **[Using level-aware calculations in Amazon QuickSight - Amazon QuickSight](https://docs.aws.amazon.com/quicksight/latest/user/level-aware-calculations.html)**
>
> Use level-aware calculations in an Amazon QuickSight analysis to insert a window or aggregate function into the order of evaluation.

---

<div class="post-metadata">

**Author:** ![olgetta](https://avatars.discourse-cdn.com/v4/letter/o/eada6e/32.png) [@olgetta](https://community.amazonquick.com/u/olgetta)\
**Post date:** [April 17, 2023, 5:29pm UTC](https://community.amazonquick.com/t/nesting-of-aggregate-functions-is-not-allowed/12302/3 "2023-04-17T17:29:33Z")

</div>

Hello @Max,  
thanks for looking into my question!  
I’ve changed (already includes WSL calculation)

> [@olgetta](#):
>
> avg(ifelse(job\_id=${Job1},(2 \* sqrt({WSL\_calculated\_job\_1} \* (1 - {WSL\_calculated\_job\_1})/sum({number\_workers})) \* 100), NULL))

to (changed sum to sumOver too since I got nesting error for it roo)  
avg(2 \* sqrt(avgOver({WSL},[{job\_id}], PRE\_AGG) \* (1-avgOver({WSL},[{job\_id}], PRE\_AGG))/sumOver({number\_workers}, [{job\_id}], PRE\_AGG))\*100,[{job\_id}])

how can I visualize it for specific {job\_id} = ${Job1}? It does not allow me to add ifelse. Im drawing a line chart

---

<div class="post-metadata">

**Author:** ![Max](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/max/32/2288_2.png) [@Max](https://community.amazonquick.com/u/Max)\
**Post date:** [May 8, 2023, 7:28pm UTC](https://community.amazonquick.com/t/nesting-of-aggregate-functions-is-not-allowed/12302/4 "2023-05-08T19:28:09Z")

</div>

@olgetta Can you just filter using a parameter on your visual?

 ![image](https://d1wl4jav5dp96l.cloudfront.net/original/2X/f/ff5f20edbfb7112d85b38cfa3c9c2968307c3308.png)
