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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How do I get the proportions in a stacked bar chart to add up to 100% for each year?


I am trying to get the proportions for each age group to add up to 100% in each year in the following bar chart -

proportions.png

The expression I am using is -

SUM(sales)/SUM(TOTAL(sales))

But it's not working.

Can anyone help?

Thanks

Greg

1 Solution

Accepted Solutions
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Put the name of your year dimension in <, > brackets after the total keyword:

SUM(sales)/SUM(TOTAL <...YourYearDimensionHere...> sales)


talk is cheap, supply exceeds demand

View solution in original post

8 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Put the name of your year dimension in <, > brackets after the total keyword:

SUM(sales)/SUM(TOTAL <...YourYearDimensionHere...> sales)


talk is cheap, supply exceeds demand
rahulgupta
Partner - Creator III
Partner - Creator III

Hi Greg,

You Current Scenario:

1. Dimension: Year

2. Dimension: AgeGroup

3. Expression: Sum(Sales)

As per your requirement, you have to use:

1. Dimension: Year

2. Expression: Sum({<AgeGroup = {"Age Under 16"}>}Sales)

3 Expression: Sum({<AgeGroup = {"Age 16-19"}>}Sales)

4. Expression: Sum({<AgeGroup = {"Age 20-24"}>}Sales)

5. Expression: Sum({<AgeGroup = {"Age 25 and over"}>}Sales)

Please apply and revert. Hope this helps

Warm Regards

Rahul

Anonymous
Not applicable
Author

Thanks Gysbert.

Anonymous
Not applicable
Author

On a similar issue, I have highlighted two of the age groups in the following line chart and I am trying to show the proportions for each year.

proportions2.png

I've tried adding the <Year> in the following expression but it is not working -

Sum({$<age_group1={'B. age 16-19'}>}(sales))/Sum({$<age_group1={'A. age Under 16','B. age 16-19','c. age 20-24','d. age 25 and over'}>}(<YEAR> sales))

Do you know where I'm going wrong?

Thanks

Greg

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Your expression is missing the total keyword.


talk is cheap, supply exceeds demand
Anonymous
Not applicable
Author

I tried this but it dosnt work -

Sum({$<age_group1={'c. age 20-24'}>}(sales))/Sum({$<age_group1={'A. age Under 16','B. age 16-19','c. age 20-24','d. age 25 and over'}>}TOTAL(<Year> sales))

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

remove the parentheses around <Year> sales:

Sum({$<age_group1={'c. age 20-24'}>}sales)/Sum({$<age_group1={'A. age Under 16','B. age 16-19','c. age 20-24','d. age 25 and over'}>}TOTAL <Year> sales)


talk is cheap, supply exceeds demand
Anonymous
Not applicable
Author

Perfect!.  Thank you very much.

Greg