Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
deniscamh
Creator
Creator

Percentage display on a Stacked Bar Chart

Hello All,

Here is my issue:

I am trying to create a stacked bar chart that represents number of employees by Age group for different departments.

So I managed to do that with the following formula for meassure:

count({<[Employee Current Status Short Descrip] = {'Active','On Leave'}>} distinct EMPLOYEE)

And Dimension 1 is Department and Dimension 2 is Class(Current Age,10).

Now it works and it shows number of employees for each Age Group by department.

But what I have a request for is to represent relative % values for each Age Group by department.

So I tried something like this 

count({<[Employee Current Status Short Descrip] = {'Active','On Leave'}>} distinct EMPLOYEE)

/

count({<[Employee Current Status Short Descrip] = {'Active','On Leave'}>} total <Department> distinct EMPLOYEE)

but it does not work because one employee can be in different Age group as my data is for multiple years and by using distinct function my total is less that it suppose to be.

For Example for department 1 I have  3 employee in 20<=yr<30; 5 employee in 30<=yr<40, 10 employee 40<=yr<50. So obviously my total should be 18 bu because I have two employees that moved from one group to another during the period my total is 16 and it gives wrong results.

Does anyone has any idea how I can solve this?

Thanks

1 Solution

Accepted Solutions
sunny_talwar

Try it this way....

1) Modify your script to create Current_Age_Bucket in the script

Table:
LOAD UniqueIdentif, 
     EMPLOYEE, 
     Date, 
     [Employee Current Status], 
     FiscalYear, 
     [Employee Current Status Short Descrip], 
     [Employee Current Status Descrip], 
     [Current Age], 
     [Foundation Department],
     Class([Current Age],10) as Current_Age_Bucket
FROM
[..\..\Downloads\pull for bar chart percent.xlsx]
(ooxml, embedded labels, table is Sheet1);

2) Use this expression

Count({<[Employee Current Status Short Descrip] = {'Active','On Leave'}>} DISTINCT EMPLOYEE)
/
Sum(TOTAL <[Foundation Department]> Aggr(Count({<[Employee Current Status Short Descrip] = {'Active','On Leave'}>} DISTINCT EMPLOYEE), [Foundation Department], Current_Age_Bucket))

image.png

View solution in original post

10 Replies
sunny_talwar

Can you check if this works for you

Count({<[Employee Current Status Short Descrip] = {'Active', 'On Leave'}>} DISTINCT EMPLOYEE)
/
Aggr(NODISTINCT Count({<[Employee Current Status Short Descrip] = {'Active', 'On Leave'}>} DISTINCT EMPLOYEE), Department)
deniscamh
Creator
Creator
Author

Unfortunately it still produced the distinct count.

Thanks for a quick replay. 

sunny_talwar

Would you be able to share some mocked up data to see the issue?
deniscamh
Creator
Creator
Author

Please see the attached file with the data I am working with.

 

sunny_talwar

Try it this way....

1) Modify your script to create Current_Age_Bucket in the script

Table:
LOAD UniqueIdentif, 
     EMPLOYEE, 
     Date, 
     [Employee Current Status], 
     FiscalYear, 
     [Employee Current Status Short Descrip], 
     [Employee Current Status Descrip], 
     [Current Age], 
     [Foundation Department],
     Class([Current Age],10) as Current_Age_Bucket
FROM
[..\..\Downloads\pull for bar chart percent.xlsx]
(ooxml, embedded labels, table is Sheet1);

2) Use this expression

Count({<[Employee Current Status Short Descrip] = {'Active','On Leave'}>} DISTINCT EMPLOYEE)
/
Sum(TOTAL <[Foundation Department]> Aggr(Count({<[Employee Current Status Short Descrip] = {'Active','On Leave'}>} DISTINCT EMPLOYEE), [Foundation Department], Current_Age_Bucket))

image.png

deniscamh
Creator
Creator
Author

Yes, That does the work, thank you.

The only thing I wanted to keep the Age Group as a calculated dimension so user can change the age range if they want, but I guess the only way to do it is with aggr function and it cannot be used with calculated dimension.

Am I right?

sunny_talwar

Unfortunately, what you have said is all correct. 😞

deniscamh
Creator
Creator
Author

Sound good.

Thank you for the solution.

Hope they would not insist to have the age group flexible.....

Thanks 

sunny_talwar

One, not such a great option, is to pre-calculate all the possible range parameters that the user might like to view by creating multiple class function fields and then conditionally show the bucket based on users input and use the same dimensions within the Aggr() function.