# Calculation of percent of difference issue

**URL:** <https://community.amazonquick.com/t/calculation-of-percent-of-difference-issue/44893>\
**Category:** Q&A\
**Tags:** error, developer, quick-sight\
**Created:** [April 10, 2025, 4:32pm UTC](https://community.amazonquick.com/t/calculation-of-percent-of-difference-issue/44893 "2025-04-10T16:32:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sanders77](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@Sanders77](https://community.amazonquick.com/u/Sanders77)\
**Post date:** [April 10, 2025, 4:32pm UTC](https://community.amazonquick.com/t/calculation-of-percent-of-difference-issue/44893/1 "2025-04-10T16:32:47Z")

</div>

I am able to find the avgover using the following calculated field.

avgOver({current\_balance}, [{screen\_group}, tier1, tier2, tier3, tier4, tier5, {account - desc}], PRE\_FILTER) ) .

However when I try to use this in formula below results do not generate expected results.  
( {current\_balance} - avgOver({current\_balance}, [{screen\_group}, tier1, tier2, tier3, tier4, tier5, {account - desc}], PRE\_FILTER) )  
/ abs(avgOver({current\_balance}, [{screen\_group}, tier1, tier2, tier3, tier4, tier5, {account - desc}], PRE\_FILTER)) \* 100

This should generate Calculate the Difference:

1. **Calculate the Difference** : Difference=25,000−733.33=24,266.67
2. **Calculate the Percent Difference** : Percent Difference=(733.33/24,266.67​)×100≈3,312.00%

However I see result of  
 ![image](https://d1wl4jav5dp96l.cloudfront.net/original/3X/e/5/e55a4c184d9d50b3d9ad4029e6dbf47cf696af89.png)

I am confused as to why the avgover works as stand alone calculation but not in second calculated field.

---

<div class="post-metadata">

**Author:** ![Hrolol](https://avatars.discourse-cdn.com/v4/letter/h/b3f665/32.png) [@Hrolol](https://community.amazonquick.com/u/Hrolol)\
**Post date:** [April 11, 2025, 6:54am UTC](https://community.amazonquick.com/t/calculation-of-percent-of-difference-issue/44893/2 "2025-04-11T06:54:36Z")

</div>

@Sanders77 , not sure, but probably you see a result of aggregation. In plain words, if this result is collected from many rows, you are aggregating precents instead of aggregating {current\_balance}. If there are many rows with very small amounts it probably could affect results, but the difference seems to be too big for this. Anyway, you could try something like this:

( sum({current\_balance}) - avg( avgOver(..) ) / abs( avg( avgOver(..) ) )

You can use min() or max() instead of avg(), it does not matter because the value should be the same in all rows within a window.

Optional: No need to do \*100, just use the proper format: “Show as: PERCENT” instead of “Show as: NUMBER”.

---

<div class="post-metadata">

**Author:** ![Sanders77](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@Sanders77](https://community.amazonquick.com/u/Sanders77)\
**Post date:** [April 11, 2025, 1:48pm UTC](https://community.amazonquick.com/t/calculation-of-percent-of-difference-issue/44893/3 "2025-04-11T13:48:19Z")

</div>

afraid adding sum to current\_balance results in error below.

Mismatched aggregation. Custom aggregations can’t contain both aggregated and nonaggregated fields, in any combination.

You are correct on dropping the \* 100 at end and change to percent. However afraid that still leaves question of why calculation is different from one calculated field is different when same algorithm is used in larger calculated field.

---

<div class="post-metadata">

**Author:** ![Sanders77](https://avatars.discourse-cdn.com/v4/letter/s/22d042/32.png) [@Sanders77](https://community.amazonquick.com/u/Sanders77)\
**Post date:** [April 21, 2025, 8:46pm UTC](https://community.amazonquick.com/t/calculation-of-percent-of-difference-issue/44893/4 "2025-04-21T20:46:56Z")

</div>

Still looking for help understanding why results are not as expected.

---

<div class="post-metadata">

**Author:** ![WLS-D](https://d2orw1595917va.cloudfront.net/user_avatar/community.amazonquick.com/wls-d/32/36109_2.png) [@WLS-D](https://community.amazonquick.com/u/WLS-D)\
**Post date:** [May 13, 2025, 3:44pm UTC](https://community.amazonquick.com/t/calculation-of-percent-of-difference-issue/44893/5 "2025-05-13T15:44:05Z")

</div>

Hello @Sanders77

Are you still working through this issue or were you able to find a solution?

The error happens because of the LAC functions. To troubleshoot could you try `sumOver({current_balance}, [], PRE_FILTER)`. Let me know if that gives a new error or the same error.

For nesting aggregations I recommend checking out this blog from a community expert:

> [@Level-Aware Calculations: Tips and Best Practices](https://community.amazonquick.com/t/level-aware-calculations-tips-and-best-practices/17936):
>
> Level-Aware Calculations (LAC) are powerful functions that allow us to perform calculations at a granularity level which is different from the granularity of our datasets and/or visuals. The sample dataset referenced by this article is a dataset of product orders placed by customers. Each order can contain multiple products and each product in an order has a unique Line Item ID. Each row of our dataset represents one line item but we want to per…
