Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
srkase
Helper IV
Helper IV

need to calculate cumulative total and percentage

Hi all

Thanks in advance.

I need the result like this

 

Regards

 

SRK

 Data   
PRODUCTqty%**bleep****bleep**%
P1397025.64%397025.64
P5300019.38%697045.02
P7201313.00%898358.0185
P4200012.92%1098370.9359
p3200012.92%1298383.8533
P810006.46%1398390.312
P210006.46%1498396.7707
DEMO5003.23%15483100
Grand Total15483100.00%  

 

My data is like this...

YEARSHORTNAMEDEALERTYPEPRODUCTAPRMAYJUNJULAUGSEPOCTNOVDECJANFEBMARTOTAL QTYTOTALVALYEAR
20182019DEMODEMOSTD       DEMO0050000000000050023397.52018
20182019CBED1STDP103000000000000030001435802018
20182019CBED1STDP20100000000000001000691102018
20192020CBED2STDP10970000000000097072284.42019
20192020CBED2STDP40200000000000002000957202019
20192020CBED3STDP503000000000000030001435802019
20202021CBED3STDp30200000000000002000957202020
20202021CBED4STDP7020130000000000201396342.22020
20202021CBED4STDP8010000000000000100046902.82020
1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Here is a sample implementation.

lbendlin_0-1637807957466.png

Thanks for the **bleep** joke.

 

PBIX is attached.

View solution in original post

9 REPLIES 9
lbendlin
Super User
Super User

Here is a sample implementation.

lbendlin_0-1637807957466.png

Thanks for the **bleep** joke.

 

PBIX is attached.

This works so well for a task i'm working on. But I'd like to understand the logic behind it instead of just copy your finished work. Can you walk me through the DAX (put as simply as it can be) if you don't mind? Highly appreciated! Thank  you!

The measure [Rnk]  computes the ranking across all products in the table, regardless of any applied filters. (it behaves much like a calculated column, but this can be modified if you need flexibility/filters)

Rnk = RANKX(ALL('Table'[PRODUCT]),calculate(sum('Table'[Val])))

The cumulative value needs to summarize the value for the "current" product and all products that have a "higher" (ie smaller) rank. However this doesn't work for the Row Subtotal as that would then overcount the sum (it would add 1+1+2+1+2+3+1+2+3+4 etc).  

 

This issue can be turned sideways to make it an advantage.

var ta = SUMMARIZE(ALLSELECTED('Table'),'Table'[PRODUCT],"SM",sum('Table'[Val]))

ta is a table variable that lists the individual products and their sums.  If we are in a table cell we need to grab the subset of the results as per [Rnk] but in the Row SubTotal we can use the entire table.

 

var t = topn([Rnk],ta,[SM],DESC)

t is another table variable, but this time it only fetches the rows from 1 to [Rnk] from our summary table based on the sum being sorted descending. This is a little cheeky as we are abusing the [Rnk] measure for row selection. Technically you could have done the same with a proper RANKX, but where's the fun in that?

 

The last thing we have to do is figure out where in the table/matrix we are.  if HASONEVALUE is true then we are in the table cell, otherwise we are in the row subtotal.  

return if(hasonevalue('Table'[PRODUCT]),sumx(t,[SM]),sumx(ta,[SM]))

for the table cell we provide the sum of sums of the sub-table t, for the row subtotal it is the sum of sums of the full table ta.

thanks a lot ... 

Is it possible to count the number of products for cumulative % total ?

ie.,

Total number of products upto 50% - 2

Total number of products upto 90% -  5

 

Total number of products upto 100% - 9

 

 

 

That's basically the rank. Add the "rnk" field to the output.

Rank gives only the ranking based on value  from 1 to ......

 

But I need the count of products

 

Results like

Contribution by products based on **bleep**%No of products
50%2
90%5
99%7
100%8

 

 

 

 

 

 

 

Hi,

Your desired result is not clear.  Please show the result in an MS Excel workbook with your workings.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Ah ok. Use a Pareto chart, or provide your own ranking table to RANKX (with custom "value" items)

RANKX function (DAX) - DAX | Microsoft Docs

 

Will you always report on 50/90/99/100 or do you plan to use different cuts?

 

50/90/99/100 ... the same cuts i used to have in my repors..

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.