Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
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 !
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
...
you can use the CLASS() function as a calulated dimension
class(AGE,10,'Age')
Mansyno
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
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.
thank you all for your help,
it's help me alot
😄
regards !
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...
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
...
thank you mr.john
regards 😄
Thanks,Your post was really useful.