Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
jessica_webb
Creator III
Creator III

Class function for calculated values

I am creating several histograms using the class function.

Where the histogram is for a straightforward value that is being pulled from my data, I'm not having any issues.

For example

Note that 'BinWidth' is a variable which is defined by an input box

DIM:

=CLASS(AGGR(AVG({<GEN={'ALL'}>}AP_Weighted),ID),BinWidth)

EXP:

Count(DISTINCT ID)

However, I'm now trying to create a histogram with a much more complex value and here I'm coming unstuck!

The expression on its own (which works fine in a table) is:

AVG({<GEN={'ALL'}>}PriorAP)-AGGR(NODISTINCT AVG({<GEN={'ALL'}>} PriorAP),ID)

But when I try to insert that into the calculated dimension like this:

=CLASS(AGGR(AVG({<GEN={'ALL'}>}PriorAP)-AGGR(NODISTINCT AVG({<GEN={'ALL'}>} PriorAP),ID),ID),BinWidth)

I get complete nonsense!

10 Replies
jessica_webb
Creator III
Creator III
Author

Hi Sunny,

Hope you don't mind me bringing this one up again!!!

The last expression you suggested is working perfectly, but I now have an even more complex one that I'm struggling to get into my histogram!!!

As mentioned before, the expression that worked before is:


=Class(Aggr(Avg({<GEN={'ALL'}>}PriorAP)-Avg(TOTAL <ID>{<GEN={'ALL'}>} PriorAP),ID, Type, Set), BinWidth)



I am now trying to edit it to get the following expression (which works in my straight table) into the histogram:

=SUM({1<GEN={'ALL'}>}NUM)/AGGR(NODISTINCT SUM({1<GEN={'ALL'}>} NUM),ID)/AVG({1}TOTAL AGGR(SUM({1<GEN={'ALL'}>}NUM)/SUM(TOTAL <ID> {1<GEN={'ALL'}>} NUM), ID, Type_Set))

What I've tried is:

=Class(Aggr

(Sum({<GEN={'ALL'}>}NUM)/SUM({1}TOTAL <ID>{1<GEN={'ALL'}>} NUM)/

(AVG({1}TOTAL AGGR(SUM({1<GEN={'ALL'>}NUM)/SUM(TOTAL <ID> <Type_Set> {1<GEN={'ALL'}>}NUM)

,ID, Type, Set), BinWidth)



But wow... what a mess!!! Any ideas?