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: 
Not applicable

Group age data into bands as an expression

Hi guys,

I'm looking to make a Bar Chart that groups Age into bands (0-20, 21-29, 30+ etc) as an expression, with another variable as a dimension.

I assume this is some kind of Set Expression magic, but not sure how to make it work!

My Age Variable name is, suprisingly, 'Age'.

Thank you!

2 Replies
Nicole-Smith

Have a look at the class function:

class(expression, interval [ , label [ , offset ]])

Creates a classification of expressions. The bin width is determined by the number set as interval. The result is shown as a<=x<b, where a and b are the upper and lower limits of the bin. The x can be replaced by an arbitrary string stated in label. 0 is normally the default starting point of the classification. This can be changed by adding an offset.

Examples:

class( var,10 ) with var = 23 returns '20<=x<30'

class( var,5,'value' ) with var = 23 returns '20<= value <25'

class( var,10,'x',5 ) with var = 23 returns '15<=x<25'


You can then change how the values are displaying using string functions.

hic
Former Employee
Former Employee

No, it is not any Set Analysis magic. But it is a calculated dimension (Edit button on the Dimension sheet).

You can use the class function, like Nicole suggests:

=Class(Age,10)

or you make an if() function:

=If( Age<=20, Dual('0-20',15),

     If( Age<=30, Dual('21-29',25),

     If( Age<=40, Dual('30-39',35),

     Dual('40+',45)

)))

HIC