Forum Discussion
How to do different calculation when drillup
Hi All
Thanks in Advance.
Im stuck with this requitement, it would be great if i get some help.
I have this wiered requirement, that, the drill up to higher level should do a different calculation based on the results from the previous level . Is this ever possible.
Matrix At Lower Level (SubCategory :
In the table below, category, subcategory, density and price i get from source table
I have a measure in report to calculate cost=Density*Price
Calculation at this hierarchy level is the cost
| Category | Subcategory | Density | Price | cost |
| Packets | Plastic | 1000 | $50 | $50000 |
| Packets | Plastic1 | 1000 | $50 | $50000 |
| Packets | Plastic2 | 850 | $40 | $34000 |
| Cups | Paper | 550 | $55 | $30250 |
| Cups | Paper1 | 550 | $47 | $25850 |
Matrix when drill up to Category 2
Sshould show up like below. Basically, calculation here is the price, which is
sum (cost for the category) from previous hierarchy level divided by
sum (density for the category) in the previous hierarchy level
| Category | Density | Price | cost |
| Packets | Sum(1000+1000+850) =2850 | Formula =Cost/density 134000/2850=47.017 | sum(50000,50000,34000)=134000 |
| Cups | Sum(550+550)=1100 | 56100/1100=51 | sum(30250+25850)=56100 |
I tried several methods but stil no success. Not sure if i have explained it clearly.
Can someone help?
3 Replies
- AllisonKennedyCommunity ChampionWhat you have explained will result in a circular reference error as Cost at product level needs Price to be calculated, so we can't use that same cost to calculate the price again without it being in a separate field/measure /column.
You will need to use something like SUMX ultimately to do what you want. - kriscoupeSolution Supplier
Hi siva6063,
You'll need to use a SUMX formula for this one. Something along these lines
SUMX( YourTable, Density * Price )This effectively iterate through all rows of YourTable calculating Density * Price and then adds them all up. This measure should work no matter what level you then drill into.
Hope it helps. If I answered your question please mark my answer as a solution so others can find this in the future.
Kris
- AnonymousNot applicable
Hi siva6063 ,
Write a measure llike this.
Values = VAR _inscopecat = ISINSCOPE ( 'Table'[Category] ) VAR _inscopesub = ISINSCOPE ( 'Table'[Subcategory] ) VAR _totalpricebycat = CALCULATE ( SUM ( 'Table'[Price] ), ALLEXCEPT ( 'Table', 'Table'[Category] ) ) VAR _totaldensitybycat = CALCULATE ( SUM ( 'Table'[Density] ), ALLEXCEPT ( 'Table', 'Table'[Category] ) ) VAR _totalcost = SUMX ( 'Table', 'Table'[Density] * 'Table'[Price] ) VAR _totalcostbycat = SUMX ( FILTER ( ALL ( 'Table' ), 'Table'[Category] = MAX ( 'Table'[Category] ) ), 'Table'[Density] * 'Table'[Price] ) RETURN SWITCH ( TRUE (), _inscopesub = TRUE (), DIVIDE ( _totalcostbycat, _totaldensitybycat ), _inscopecat = TRUE (), _totalcost )Regards,
Harsh NathaniDid I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)