Multiple aggregation calculations are showing errors when using with Lag Function

Hello
I have a Pivot table , where My Active head count and Expected Headcount sre dependent on each other. But I am facing some issues with the calculation

image
image

Now I need to Add this active headcount +hires+terms to get expected ending headcount. But while doing that i am getting aggregation error
image

I tried to add the aggregation along with hires and terms, then I am getting another error saying that there is an error in the calculation. Can anyone help to get the proper calculation for this scenario?
https://community.amazonquicksight.com/t/creating-grid-report-with-option-to-have-user-input-on-cells/32988/7

Hi @DylanM ,could you please help on this? Since the calculation is cyclical, while trying to solve active , Expected is breaking, while trying to solve expected , active is breaking

Hello @Ganga, since we are continuing from a previous topic, I will close out the last question and we can continue from here. Initially, I will say, creating a demo version of this analysis in QuickSight Arena will make it a lot easier for us to debug the issues you are facing.

As for the aggregation error you are facing, are your hires and terms fields also calculated fields? If so, can you please share those with me as well?

1 Like

Hi @DylanM , These are the calculations that i am using
1.Active headcount= ifelse(isNull({Lag for prior}),sum({active_head_count}),{Lag for prior})
2.Lag for prior= lag(sum({Expected Ending Headcount}),[date ASC],1)
3.Hires=(hires)${AddHires}
4.Terms= terms+${AddTerms}
5. Expected Ending head count= {Active headcount}+Hires+Terms

Please find the link to Quicksight Arena created for this:
Multiple Aggregation Calculation Eg

1 Like

Hello @Ganga, after spending some time with the calculations, I was able to set it up in a way that I believe resolves your issue. You can view my work here:

Multiple aggregation calculations are showing errors when using with Lag

I will mark my response as the solution, but let me know if you have any remaining questions. Thank you!

1 Like

Hi @DylanM ,
Thankyou so much for the workaround. But this is not working as expected. As I was mentioned in the Issue snapshot,

  1. For the following month of selected date, we need the Actual Active Head Count which is pulling from database (active_head_count)in Active headcount for April here. ie, 45
  2. And expected Ending headcount should be the sum of first 3 rows.
    Ie, 45+3+10= 58
  3. For next month, Active headcount should be previous month’s Expected Ending Headcount. as of now you are taking (active_head_count) instead of that.
    Ie, 58
  4. And for the Expected ending headcount for May Month should be Sum of Top 3 Rows.
    Ie, 58+9+7=74

And this 74 Have to be the Active Headcount for Jun month.

This is what we are expecting

Could you please help to rearrange the calculations to get this achieved? Thanks In Advance for your Help!!!

Here , Either we need to get a Way to do the addition of a calculated field containing lag function with other columns, or need to get if we can use any other function other than lag, so that it wont cause any circular dependency issues.

Hi All,

Can anyone help to get this issue resolved??

Hello @Ganga, I appreciate the explanation, I think I fully understand the output you are expecting.

The main issue you are going to run into here is the number of aggregation types that you are trying to utilize together. I was able to create a calculation to run the Expected Ending Headcount but I cannot also seem to return the active head count value you are expecting. Using runningSum with firstValue functions work together to get the desired result, but then I cannot nest those aggregations in a Lag function to return the previous value.

Based on my knowledge in QuickSight, you will likely not achieve the exact solution you are working towards without hitting limitations.

My best recommendation would be to utilize the Expecting Ending Headcount calculated field that I built in [Arena](Multiple aggregation calculations), while finding a different way to represent the Active Head Count row. I would not recommend trying to reference calculated fields within themselves because that will definitely lead to complicated errors. I hope this helps!

1 Like

Hi @DylanM Thankyou so much for all your help for resolving the issue.
But after doing so many workarounds I was able to get exact solution which I wanted Yesterday. I could figure out the calculations that are using. I can attach the calculations which I used here: https://community.amazonquicksight.com/t/multiple-aggregation-calculations-are-showing-errors-when-using-with-lag-function/33529/4

2 Likes

Hello @Ganga, I am glad you were able to resolve it. Thank you for letting me know!