Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
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!

1 Solution

Accepted Solutions
sunny_talwar

May be try this

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

View solution in original post

10 Replies
sunny_talwar

You love Nodistinct, don't you? May be try this

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

avinashelite

Add KS5_LAESTAB as the Dimension you will get the result ...

In order to use AGGR you need to have that dimension in the chart

jessica_webb
Creator III
Creator III
Author

Love it... Or just blindly add it to my expressions!!

I'm afraid your suggestion didn't work. But that's my fault as I had given my example incorrectly!

Have amended it above, but to clarify I was trying to use:

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


So I tried your suggestion amended to:

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



But this gives me nothing in my chart at all!

jessica_webb
Creator III
Creator III
Author

Sorry Avinash, I gave the wrong example!

I'm actually trying to use:

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

sunny_talwar

Would you be able to share few rows of data to show what exactly are you trying to do here?

jessica_webb
Creator III
Creator III
Author

Hi Sunny,

I've attached a spreadsheet of the table that this histogram should build upon.

You'll see there's a column called 'PriorAP' which is created with the expression:

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

What I would want to see in the Histogram is essentially the number of rows that fall into each bin. I've realised now actually that referring to 'ID' in my expression perhaps doesn't make sense, as I'm not really interested in distinct or non-distinct IDs...

So for example, with the attached data, if I set my bin width to 0.5, I would expect to see frequencies approximately of:

BinFrequency
-12.51
-12
-11.5
-11
-10.5
-10
-9.5
-9
-8.5
-8
-7.51
-7
-6.5
-62
-5.52
-51
-4.51
-4
-3.54
-32
-2.55
-24
-1.51
-112
-0.57
0
0.521
19
1.56
23
2.54
32
3.5
4
4.51
5
antoniotiman
Master III
Master III

Like this ?

sunny_talwar

May be try this

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

jessica_webb
Creator III
Creator III
Author

Hi Sunny,

After a lot of testing, I think that's working..!

So the full expression I'm using is:

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

Thanks once again for your help

Jess