Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

[ASK] basic Qlikview, VALUE BETWEEN in PIE CHART

hello newbie need help.. 😄

in my customer database has a [BirthDate] field.

to get customer age,

i use :

year(today() - year(BirthDate) as Age,

and, in pie chart

i use dimension [Age], and expresion [sum(sales)],

from that i can see Sales by Customer Age.

but the problem is,

the pie chart show in all age. not in range

the question is,

can i set range between age in pie chart?

example,

the pie show Sales by,

age(>=10<=20) as 10 - 20 years

age(>=30<=40) as 30 - 40 years

etc..

plis help.

thank you..

regards !

1 Solution

Accepted Solutions
johnw
Champion III
Champion III

As Mike suggested, use the age() function. Simple subtraction of years doesn't work. If I was born December 31, 1990, I'm 19 years old, not 20 years old. As for establishing ranges without class(), I'd just nest some if() functions for something this simple. And I'd use a preceeding load to avoid calculating the Age multiple times. And I'd use the dual() funtion for easy sorting in numeric order.

LOAD *
,if(Age<20,dual('<=19',1)
,if(Age<30,dual('20-29',20)
,if(Age<40,dual('30-39',30)
,if(Age<60,dual('40-59',40)
,if(Age<80,dual('60-79',60)
,dual('>=80',80)))))) as "Age Range"
;
LOAD
...
,age(today(),BirthDate) as Age
...

View solution in original post

8 Replies
wizardo
Creator III
Creator III

you can use the CLASS() function as a calulated dimension

class(AGE,10,'Age')

Mansyno

Pablo_Robles
Partner - Contributor III
Partner - Contributor III

Hi Frozenring,

You can resolve this issue with the class function in a calculated dimension. The class function classifies the values in delimited ranges via interval. In your case, the sintax would be class(age,10,'Age') and the results are like this : 10 <= Age < 20, 20 < Age > 30 ... If you don´t specificate the third parameter, the word Age will be changed with an x.

The complete syntax is class(expression, interval, [,label] [,offset]). You can get more information in QlikView help.

Another method to resolve this issue is create a INLINE table with the ranges, because the class funcion format is not very attractive. You can combine class function in the script with a INLINE table in order to create your own format.

Good luck,

Pablo Robles

mike_garcia
Luminary Alumni
Luminary Alumni

Well, your question has been answered, but I would like to point out that you can also use the Age() function to calculate the age.

Regards,

Mike.

Miguel García
Qlik Expert, Author and Trainer
Not applicable
Author

thank you all for your help,

it's help me alot

😄

regards !

Not applicable
Author

hello wizardo, pablo and mike i have already tried class function,

but the result is not good enough, because the range between age is fix by 10.

i want to set a diferrent range in age,

this is my range between age,

>=80

60 - 79

40- 59

30-39

20-29

<=19

i have tried load it by INLINE too, but it doesn't work properly,

maybe wrong in syntax, plis help me

this is what i type,

LOAD * INLINE [

Age, Age_Range

>= 80, 80 Above

>=60<=79, 60 - 79

>=40<=59, 40- 59

>=30<=39, 30 - 39

>=20<=29, 20 - 29

<=19, Under 19

];

the syntax above won't work,

plis can somebody help?

regards...

johnw
Champion III
Champion III

As Mike suggested, use the age() function. Simple subtraction of years doesn't work. If I was born December 31, 1990, I'm 19 years old, not 20 years old. As for establishing ranges without class(), I'd just nest some if() functions for something this simple. And I'd use a preceeding load to avoid calculating the Age multiple times. And I'd use the dual() funtion for easy sorting in numeric order.

LOAD *
,if(Age<20,dual('<=19',1)
,if(Age<30,dual('20-29',20)
,if(Age<40,dual('30-39',30)
,if(Age<60,dual('40-59',40)
,if(Age<80,dual('60-79',60)
,dual('>=80',80)))))) as "Age Range"
;
LOAD
...
,age(today(),BirthDate) as Age
...

Not applicable
Author

thank you mr.john

regards 😄

jafari_ervin
Creator III
Creator III

Thanks,Your post was really useful.