7 Replies Latest reply: Sep 18, 2014 11:59 PM by jagan mohan rao appala

# Bar chart question sum or count ?

Hi,

Im trying to build a bar chart that will separate the peoples age in different categories

here is my data

NAMEAGE

pierre

45
jean23
peter13
michael11
albert8
patricia5

I want my bar chart to represent how many people are under 7 / between 7 and 14 / upper than 14

I cant get to find the right expression to do so.

Can someone help , im sure it is not so complicated but im a very beginner

• ###### Re: Bar chart question sum or count ?

Hi,

You need to use intervalmatch functionality :

T1:

[Name, Age

pierre,45

jean,23

peter,13

michael,11

albert,8

patricia,5];

Interval:

[Start, End, Description

0,6, <7

7,13, 7-14

14,99, >14];

BridgeTable:

IntervalMatch (Age)

Load distinct Start, End Resident Interval;

• ###### Re: Bar chart question sum or count ?

do you see any way to do it without a bridge table? directly in the formula of the chart ?

• ###### Re: Bar chart question sum or count ?

Hi,

Try like this in script

Data:

If(Age > 14, 'Over 14',

If(Age >= 7, '7 - 14', 'Under 7')) as AgeGroup;

Name, Age

pierre, 45

jean, 23

peter, 13

michael, 11

albert, 8

patricia, 5

];

Regards,

Jagan.

• ###### Re: Bar chart question sum or count ?

see attachment

• ###### Re: Bar chart question sum or count ?

Hello,

What if my name name colum contains 10000 records?

I was thinking of building a chart referencing the table and for each bar of the chart make a formula without using alternative table,

i will write it in natural language as i am not sure of the qlikview

so i wanna see the number of people on the vertical axis

on the horizontal the bar with the number of people under 7 years for example

so for this write something like

if age under 7 then count the number of people and display it : i would label it <7 years

if age between 7 and 15 then count number of people etc...

I am just not sure that your solution is adaptable to my scale of people, or is it?

Thanks

• ###### Re: Bar chart question sum or count ?

You may use script similar to the one below. Use AgeGroup as Dimension and Count(NAME) as Expression in a bar chart.

Data:

LOAD *,If(AGE < 7,'Under 7',If(AGE > 14,'Over 14','7 - 14')) as AgeGroup;
NAME, AGE
pierre, 45
jean, 23
peter, 13
michael, 11
albert, 8
patricia, 5
]
;

• ###### Re: Re: Bar chart question sum or count ?

you can manage with class function and if as already posted (in the attachment 10000 different names)

you can also calculate every bar with an expression (last sheet in the attachment)