Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Calculated Dimension

Hi All

I have a very simple question for Calculated Dimension.

I have a field in which I have values starting from 1 to 50

I want to calculate dimensions to categorise these values like below

1 day

5 to 10 days

10 to 15 days

15 to 20 days

greater than 20 days

I am using the following script.

=if([Length of stay]=1,'1 day',
if([Length of stay]>1 and [Length of stay]<=5,'2 to 5 days',
if([Length of stay]>5 and [Length of stay]<=10,'6 to 10 days',
if([Length of stay]>10 and [Length of stay]<=15,'11 to 15 days',
if([Length of stay]>15 and [Length of stay]<=20,'16 to 15 days',
if([Length of stay]>21,'greater than 21 days','other'))))))

I think this is working fine but my legend is showing me this code and when i hover over chart I am also seeing this code I want to see the numbers instead of code

Cananyone help me please?

Many thanks in advance

Regards,

Waqas

1 Solution

Accepted Solutions
Not applicable
Author

If you add a label to the calculated dimension, you will then not see the expression and see the label

View solution in original post

8 Replies
Not applicable
Author

If you add a label to the calculated dimension, you will then not see the expression and see the label

johnw
Champion III
Champion III

A little off topic, but since the IF statements are checked in sequence, you can simplify:

=if([Length of stay] = 1, '1 day',
if([Length of stay]<= 5, '2 to 5 days',
if([Length of stay]<=10, '6 to 10 days',
if([Length of stay]<=15,'11 to 15 days',
if([Length of stay]<=20,'16 to 20 days',
if([Length of stay]> 21,'greater than 21 days'
,'other'))))))

You might also be better off moving this expression into your script, establishing a [Length of Stay Group] or some such. That would also incidentally fix your original problem.

disqr_rm
Partner - Specialist III
Partner - Specialist III

You should be able to use class() function in the script to calculate this field.

In any case, as John said, you would be better off moving this code to your script.

johnw
Champion III
Champion III


Rakesh wrote:You should be able to use class() function in the script to calculate this field.


Except that the intervals aren't even. Some of them are, but not all.

Anonymous
Not applicable
Author

Thak you so much Neil, John and Rakesh.

At the moment i have fixed this problem as Neil suggested but i would like to know how can I move this to my script, as I know when the data grows calculated dimension is not a good idea. John can you please help me with this?

Rakesh can you please tell me about Class function? how is works with the help of an example. I want to learn it.

Many thanks in advance.

Regards,

Waqas

Waqas

Anonymous
Not applicable
Author

Hi all again

I used John's post to move my If statement to script - working perfectly fine 😉

here is the link

http://community.qlik.com/forums/p/22135/84583.aspx#84583

I am still waiting for the Class function though

Cheers

Waqas

disqr_rm
Partner - Specialist III
Partner - Specialist III

Enclosed is an example of Class. Pretty useful, but only if you have equal rage values.

Anonymous
Not applicable
Author

Thank you so much Rakesh. It was indeed very helpful.

Kind Regards,

Waqas