Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
pam1990
Contributor III
Contributor III

How to construct class function with > and < as the ends of the range?

How do I construct the class function to create the following two ranges?

RANGE 1

>2
1.75-2
1.5-1.75
1.25-1.5
1-1.25
<1

 

RANGE 2

<7070-8080-90>100
Labels (3)
1 Solution

Accepted Solutions
GaryGiles
Specialist
Specialist

If you are trying to do this in a Qlik Sense chart, you could use:

=aggr(Only(if([fieldname]<1,'<1',if(Value>2,'>2',Replace(Class([fieldname],.25),' <= x < ','-')))), [fieldname])

You would want to sort descending by max([fieldname]).

=aggr(Only(if([fieldname]<70,'<70',if(Value>100,'>100',Replace(Class([fieldname],10),' <= x < ','-')))), [fieldname])

You would want to sort ascending by max([fieldname]).

On Range 2, it looks like you left out 90-100.

Also, you don't have to enclose the if statement within an aggr().  It depends on what behavior you are looking for is a user selects a value in the field.  With aggr() this first expression would look like:

=if([fieldname]<1,'<1',if(Value>2,'>2',Replace(Class([fieldname],.25),' <= x < ','-')))

Also, the if statement is what you could use if you were creating it in the load script.

Hope that helps.

View solution in original post

6 Replies
GaryGiles
Specialist
Specialist

If you are trying to do this in a Qlik Sense chart, you could use:

=aggr(Only(if([fieldname]<1,'<1',if(Value>2,'>2',Replace(Class([fieldname],.25),' <= x < ','-')))), [fieldname])

You would want to sort descending by max([fieldname]).

=aggr(Only(if([fieldname]<70,'<70',if(Value>100,'>100',Replace(Class([fieldname],10),' <= x < ','-')))), [fieldname])

You would want to sort ascending by max([fieldname]).

On Range 2, it looks like you left out 90-100.

Also, you don't have to enclose the if statement within an aggr().  It depends on what behavior you are looking for is a user selects a value in the field.  With aggr() this first expression would look like:

=if([fieldname]<1,'<1',if(Value>2,'>2',Replace(Class([fieldname],.25),' <= x < ','-')))

Also, the if statement is what you could use if you were creating it in the load script.

Hope that helps.

pam1990
Contributor III
Contributor III
Author

These worked great. Thank You

pam1990
Contributor III
Contributor III
Author

Something odd is happening though. There is a range of 2-2.25, which should be the >2 range. Here is what I added to the load script. 

if(DCR<1,'<1',if(DCR>2,'>2',Replace(Class(DCR,.25),' <= x < ','-'))) as DCR_RANGE

Where you have Value, I put the field name. Is that where I went wrong??

pam1990_0-1619725670408.png

 

pam1990
Contributor III
Contributor III
Author

I know why it is happening. There are a couple where the DCR is exactly 2. I want those to be in the 1.75-2 range.

GaryGiles
Specialist
Specialist

What is the precision of DCR?  Could you subtract a non-substantial amount from the DCR field in the Class() function like this to keep 2.0 in the 1.75-2 group:

if(DCR<1,'<1',if(DCR>2,'>2',Replace(Class(DCR-.0000001,.25),' <= x < ','-'))) as DCR_RANGE

pam1990
Contributor III
Contributor III
Author

I believe I got this working. Thank You @GaryGiles .