Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

toddbuss
New Contributor III

formatting with Class function

I have a range representing a count of days.  The functions below categorize them into 5 year segments for the X axis of a histogram. 

this one works, but is incomplete:

subfield(class(Days_to_TRD/365,5),' <= x < ',1) & '-'

this one stops showing any values:

subfield(class(Days_to_TRD/365,5),' <= x < ',1) & '-'& subfield(class(Days_to_TRD/365,5),' <= x < ',2)-1


It's as if Qlik doesn't know how to define the buckets when more than one class statement is used.  Can anyone tell me what I'm doing wrong?

Do I need to create the classes during the data load instead?

Tags (1)
1 Solution

Accepted Solutions
mangalsk
Contributor III

Re: formatting with Class function

=Dual(Replace(Class(Days_to_TRD/365,5),'<= x <','to'), Num(Class(Days_to_TRD/365,5)))

6 Replies
antoniotiman
Honored Contributor III

Re: formatting with Class function

Hi Todd,

try this

Floor(Days_to_TRD/365,5)&'-'&(Floor(Days_to_TRD/365,5)+4)

Regards,

Antonio

Re: formatting with Class function

Class has a third parameter which could define how class displays the results - therefore try just this:

class(Days_to_TRD/365,5, '-')

Beside them your second approach couldn't work because it creates a pure string-value and not a numeric number. If you want to display a certain formatting (which couldn't be reached with a formatting-function) you need to use a dual-function in which the string-part could be manipulated in various ways, for example with any string-functions maybe like this:

dual(replace(class(Days_to_TRD/365,5), ' <= x < ', '-'), num(class(Days_to_TRD/365,5)))

- Marcus

balabhaskarqlik
Honored Contributor

Re: formatting with Class function

Try this:

Replace(Class(Days_to_TRD/365,5),'<= x <', '1')& '-'& Replace(Class(Days_to_TRD/365,5),'<= x <', '2')-1


balabhaskarqlik
Honored Contributor

Re: formatting with Class function

=dual(REPLACE(CLASS(Days_to_TRD/365,5), '<= x <','1') & '-', CLASS(Days_to_TRD/365,5))

mangalsk
Contributor III

Re: formatting with Class function

=Dual(Replace(Class(Days_to_TRD/365,5),'<= x <','to'), Num(Class(Days_to_TRD/365,5)))

toddbuss
New Contributor III

Re: formatting with Class function

thanks.  The Dual function is new to me.  The formula works like charm.  I'll need to learn more about Dual.  :-)

Community Browser