Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
amweiner
Partner - Contributor III
Partner - Contributor III

How to compute a total in pivot table as the distribution of the total

I created a pivot table that contains two dimensions (Category and Type). These are the raw numbers.

This is the original numeric data:
CategoryTypeType 1Type 2Type 3Type 4Type 5Type 6Type 7Type 8Type 9Total
CAT1 2,884,362139,386496,090188,193240,5061,796,7042,094,880223,26108,063,382
CAT2 535,05824,7512,730309,471015,556038,1260925,692
CAT3 16,656,022578,8862,256,4231,741,5302,372,081369,56530,588609,552024,614,647
CAT4 10,026,812356,5421,318,8081,443,051647,855955,2162,015,666793,732017,557,682
CAT5 123,73960,385897,485719,268788405,52623,260121,2892,6002,354,340
CAT6 13,130,509451,8421,015,460748,945386,240934,2071,800,988618,707019,086,898
CAT7 1,210,35640,12882,72042,152117,47239,18845,031126,15101,703,198
CAT8 178,2288,8265,167375,10330,470187,4832,803,386148,45003,737,113
Total 44,745,0861,660,7466,074,8835,567,7133,795,4124,703,4458,813,7992,679,2682,60078,042,952

I need to calculate these as percentages, so that each row is a distribution of that row, and totals to 100%. I used the following expression to do this. Everything is fine with the exception of the total line. I want the total line to be a distribution across the total, not the sum of each type.

sum(AMT) / aggr(NODISTINCT sum(AMT),Category)

CategoryTypeType 1Type 2Type 3Type 4Type 5Type 6Type 7Type 8Type 9Total
CAT1 36%2%6%2%3%22%26%3%-100%
CAT2 58%3%0%33%-2%-4%-100%
CAT3 68%2%9%7%10%2%0%2%-100%
CAT4 57%2%8%8%4%5%11%5%-100%
CAT5 5%3%38%31%0%17%1%5%0%100%
CAT6 69%2%5%4%2%5%9%3%-100%
CAT7 71%2%5%2%7%2%3%7%-100%
CAT8 5%0%0%10%1%5%75%4%-100%
Total --------0%-

This is the desired result. How can I get qlikview to display the percentage distribution on the total row?

CategoryTypeType 1Type 2Type 3Type 4Type 5Type 6Type 7Type 8Type 9Total
CAT1 36%2%6%2%3%22%26%3%0%100%
CAT2 58%3%0%33%0%2%0%4%0%100%
CAT3 68%2%9%7%10%2%0%2%0%100%
CAT4 57%2%8%8%4%5%11%5%0%100%
CAT5 5%3%38%31%0%17%1%5%0%100%
CAT6 69%2%5%4%2%5%9%3%0%100%
CAT7 71%2%5%2%7%2%3%7%0%100%
CAT8 5%0%0%10%1%5%75%4%0%100%
Total 57%2%8%7%5%6%11%3%0%100%
1 Solution

Accepted Solutions
amweiner
Partner - Contributor III
Partner - Contributor III
Author

That did not work.

View solution in original post

5 Replies
swuehl
MVP
MVP

Try

sum(Amt) / sum(total<Category> Amt)

amweiner
Partner - Contributor III
Partner - Contributor III
Author

That did not work.

amweiner
Partner - Contributor III
Partner - Contributor III
Author


I am attaching a qvw file that contains the data and illustrates the issue.

Not applicable


Please find attached qvw..

amweiner
Partner - Contributor III
Partner - Contributor III
Author

I tried the original solution:

(Amt)/sum(total<Category> Amt)

And it is working now. I don;t know what happened the first time I tried, though.