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

Announcements
See why IDC MarketScape names Qlik a 2025 Leader! Read more
cancel
Showing results for 
Search instead for 
Did you mean: 
patrickanderson
Partner - Contributor III
Partner - Contributor III

Aggregation in pivot table

Hello,

I am pretty sure this can be done and I am fairly sure I have done it before but I am having a brain cramp and jsut need some quick help:

I have a Pivot Table:

TDLINX Category Dollar SalesDollar Sales % Chg vs. YAGO:$ Share of Category
84Enlmgr4942016.1%100.0%
Cxpnxg119185.6%

-

Mveaqlp10534-19.1%-
ApnhtOxgop5582-7.3%

-

101

Enlmgr5613110.9%100.0%
Cxpnxg125426.4%-
Mveaqlp10391-18.7%-
ApnhtOxgop7570-9.5%-


'Enlmgr' is in the Field Category but it is more of a total of the other 3 Catergories plus a few others who arent reported.

I need to calculate the % of 'Enlmgr' is for each Category and TDLINX.

I tried

=

(sum({<$(vMaxMonth)>}[Dollar Sales])/aggr(sum({<$(vMaxMonth), Category={'Enlmgr'}>} [Dollar Sales]),TDLINX, Category)



but that didnt work I also tried the aggr around the whole expression.

Any Ideas?

1 Solution

Accepted Solutions
erichshiino
Partner - Master
Partner - Master

I think I understood it now.

If you don't mind hardcoding this category as you showed on the first post, you can include Shoes on set analysis with Total.

Thus, you can try:

sum({<$(vMaxMonth)>}[Dollar Sales])/ sum({<$(vMaxMonth), Category={Shoes}>}total <TDLINX> [Dollar Sales])



sum({<$(vMaxMonth)>}[Dollar Sales])/ sum({<$(vMaxMonth), Category={Shoes}>}total <Category> [Dollar Sales])

or



sum({<$(vMaxMonth)>}[Dollar Sales])/ sum({<$(vMaxMonth),Category={Shoes}>}total [Dollar Sales])

or

View solution in original post

6 Replies
patrickanderson
Partner - Contributor III
Partner - Contributor III
Author

Do I need to add a different level added in the script?

erichshiino
Partner - Master
Partner - Master

I didn't understand your question...

First,

You got the results only for the line with Enlmgr because you put that on the set analysis to divide the number (the calculation is only possible for this line.



do you need the % related to the total of category?

You can use total. Try:

sum({<$(vMaxMonth)>}[Dollar Sales])/ sum({<$(vMaxMonth)>}total [Dollar Sales])

or

Hope it helps,



sum({<$(vMaxMonth)>}[Dollar Sales])/ sum({<$(vMaxMonth)>}total <Category> [Dollar Sales])

or



sum({<$(vMaxMonth)>}[Dollar Sales])/ sum({<$(vMaxMonth)>}total <TDLINX> [Dollar Sales])



patrickanderson
Partner - Contributor III
Partner - Contributor III
Author

Imagine the data came in like this:

Category$$
Nike20
Adidas15
Reebok10
Shoes55


The Category Shoes is reported as a Category but it actually contains the sum of Nike, Reebok and Adidas PLUS a few other smaller shoe brand whose individual numbers are not reported. I want to calculate market share for Nike Reebok and Adidas.

Like Nike/Shoes= 20/55 = 36%

The issue is all the data comes in on the same level "Category". I could move the Shoes amount to a differnt field but I want all my other calcs to work on the Category level. Is this possible?

erichshiino
Partner - Master
Partner - Master

I think I understood it now.

If you don't mind hardcoding this category as you showed on the first post, you can include Shoes on set analysis with Total.

Thus, you can try:

sum({<$(vMaxMonth)>}[Dollar Sales])/ sum({<$(vMaxMonth), Category={Shoes}>}total <TDLINX> [Dollar Sales])



sum({<$(vMaxMonth)>}[Dollar Sales])/ sum({<$(vMaxMonth), Category={Shoes}>}total <Category> [Dollar Sales])

or



sum({<$(vMaxMonth)>}[Dollar Sales])/ sum({<$(vMaxMonth),Category={Shoes}>}total [Dollar Sales])

or

patrickanderson
Partner - Contributor III
Partner - Contributor III
Author

But would this work with multiple TDLINX? the total function woudl take the the Application total correct so if

TDLINXCategory$$
1Nike20
1Adidas15
1Reebok10
1Shoes55
2Nike25
2Adidas30
2Reebok20
2Shoes100


total $$ woudl be 155 so now NIKE Market share for TDLINX 1 would calculate as 20/155 = 12.9%

Is there any way to avoid this?

Thanks for your help by the way!! Big Smile

erichshiino
Partner - Master
Partner - Master

That will be the result for the 3rd expression, the 2nd must give the result that you want (may be the 1st Stick out tongue)