Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Creating calculated dimension

Hi

I have 3 tables with individual information, and I am trying to create a pie chart to show family status. The key fields are as folows:

ID = ID number of individuals

Role = Parent/Child

RegNo = Household Number

Capture.JPG

I am attempting to create pie charts with the following:

- Number of children in a household (Chart should show me Count(Distinct(RegNo)) with Age <=8 and Role = Child

I am currently using the code in Expressions

COUNT( {< Age = {">=0 <=15"}, Role = {Child}  >}DISTINCT(RegNo))

In Dimension, I am trying to get the pie chart to show "0 Children", "1 Child", "2 Children", ">2 Children", however I am unsure of how to proceed.

- Number of Members in a hosuehold

Expression: COUNT (DISTINCT ( RegNo))

Dimension: Should show "1 Member", "2 Members", "3 Members"....">5 Members"

Any advice will be greatly appreciated.

1 Solution

Accepted Solutions
jyothish8807
Master II
Master II

You can try something like this in Dimension:

If( Aggr(count({<Role ={'Child'}>}ID),RegNo)=0,'0 Children', if(Aggr(count({<Role = {'Child'}  >}ID),RegNo)=1,'1 Children',if(Aggr(count({<Role = {'Child'}  >}ID),RegNo)=2,'2 Children',if(Aggr(count({<Role = {'Child'}  >}ID),RegNo)=>2,'>2 Children'))))

Br,

KC

Best Regards,
KC

View solution in original post

10 Replies
jyothish8807
Master II
Master II

Hi Chay,

Can you share a sample data ? Then it will be easy for us to help.

Q1. What do you mean by dimension "0 Children", "1 Child", "2 Children", ">2 Children" when you are already showing only the children who are less than 15 yrs old ? I am a bit confused.

Br,

KC

Best Regards,
KC
jyothish8807
Master II
Master II

You can try something like this in Dimension:

If( Aggr(count({<Role ={'Child'}>}ID),RegNo)=0,'0 Children', if(Aggr(count({<Role = {'Child'}  >}ID),RegNo)=1,'1 Children',if(Aggr(count({<Role = {'Child'}  >}ID),RegNo)=2,'2 Children',if(Aggr(count({<Role = {'Child'}  >}ID),RegNo)=>2,'>2 Children'))))

Br,

KC

Best Regards,
KC
Not applicable
Author

Hi Jyothish

Apologies for the confusion.

Sample data set will be as such:

Capture.JPG

My pie chart should show something along the lines of:

Capture.JPG

jonathandienst
Partner - Champion III
Partner - Champion III

You can do it with an expression like:

If(COUNT({<Age = {">=0 <=15"}, Role = {Child}>} DISTINCT RegNo) = 0,

  Dual('0 Children', 0),

If(COUNT({<Age = {">=0 <=15"}, Role = {Child}>} DISTINCT RegNo) = 1,

  Dual('1 Child', 1),

If(COUNT({<Age = {">=0 <=15"}, Role = {Child}>} DISTINCT RegNo) = 2,

  Dual('2 Children', 2),

  Dual('>2 Children', 3)

)))

But I would recommend doing this calculation in the back-end as this sort of calculation can perform poorly in the front end if your data set is large.

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
jyothish8807
Master II
Master II

Give a try with my expression.

Best Regards,
KC
Not applicable
Author

Hi Jonathan

Thanks for the response. If I were to implement this in the back end, which table do you reckon I should place that code?

jyothish8807
Master II
Master II

Hi Chay,

Pfa sample.

Br,

KC

Best Regards,
KC
Not applicable
Author

Thanks, working well. Only issue is that the last '=>2' was causing an error, so I'm simply using >1

jyothish8807
Master II
Master II

Yes, it was fixed in the attached app.

Br,

KC

Best Regards,
KC