Skip to main content
Announcements
See why Qlik was named a Leader in the 2024 Gartner® Magic Quadrant™ for Data Integration Tools for the ninth year in a row: Get the report
cancel
Showing results for 
Search instead for 
Did you mean: 
ali_hijazi
Partner - Master II
Partner - Master II

Change the total type in expression

Hello
I got a table with 2 dimensions and several expressions
the expressions got aggregations and they are working well and giving correct results
there are two options given to the users to show on the chart either the count or the percentage

 
 

WhatsApp Image 2024-07-23 at 9.55.49 AM.jpeg

now what is required is that when the user clicks the percentage button, the total should display the average of the results and not the sum but when the count button is selected the total should display the sum

dbe47fb2-2870-4117-8c75-d5ecee8e693e.jpeg

I tried to use the dimensionality() and check what the user selected as percentage or count, and added and Avg(my_expression)
I got an error for nested aggregation not allowed
is there a way to tackle this issue?

I can walk on water when it freezes
Labels (1)
3 Replies
lennart_mo
Creator
Creator

Hi @ali_hijazi,

Qlik doesn't allow using an aggregation-function inside another aggregation normally, which is called nested aggregation.

You can bypass this by either using the TOTAL qualifier inside the inner aggregation or by using the AGGR()-Function.

Could you post your initial formula which gave you this error?

Kushal_Chawda

@ali_hijazi  let's say you have variable vType to switch % and sum, you could try below

if(Dimensionality()=0 and vType='Percentage',

avg(aggr(YourExpression,TableDimension1,TableDimension2)),

if(Dimensionality()=0 and vType='Sum',

YourSumExpression,

YourExpression

)
)

ali_hijazi
Partner - Master II
Partner - Master II
Author

Hello @Kushal_Chawda 
I tried this approach but I got an error saying nested aggregation is not allowed
that's because YourExpression is a variable with aggregation too

what I did is I created two measures one with total function Count and another with total function avg
and each measure is hidden or visible depending on whether the user selected Count or Percentage

I can walk on water when it freezes