Forum Discussion
Alvin2013
3 years agoFrequent Visitor
How to do a running total sorted by values
How to create a running total that follow the order of my chart?
This was done in Tableau. How to replicate it in PowerBI?
- Anonymous3 years ago
Hi Alvin2013 ,
I suggest you to try code as below to create a measure.
Running Total Sort by Values = VAR _SUMMARIZE = SUMMARIZE ( ALL ( 'Table' ), 'Table'[Category], "Sum", SUM ( 'Table'[Value] ) ) VAR _ADDSORT = ADDCOLUMNS ( _SUMMARIZE, "Sort", RANKX ( _SUMMARIZE, [Sum],, DESC, SKIP ) ) VAR _RUNNINGTOTAL = ADDCOLUMNS ( _ADDSORT, "Running Total", SUMX ( FILTER ( _ADDSORT, [Sort] <= EARLIER ( [Sort] ) ), [Sum] ) ) RETURN SUMX ( FILTER ( _RUNNINGTOTAL, [Category] = MAX ( 'Table'[Category] ) ), [Running Total] )Result is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
2 Replies
- Ashish_Mathur
Super User
Hi,
Share the download link of the PBI file.
- AnonymousNot applicable
Hi Alvin2013 ,
I suggest you to try code as below to create a measure.
Running Total Sort by Values = VAR _SUMMARIZE = SUMMARIZE ( ALL ( 'Table' ), 'Table'[Category], "Sum", SUM ( 'Table'[Value] ) ) VAR _ADDSORT = ADDCOLUMNS ( _SUMMARIZE, "Sort", RANKX ( _SUMMARIZE, [Sum],, DESC, SKIP ) ) VAR _RUNNINGTOTAL = ADDCOLUMNS ( _ADDSORT, "Running Total", SUMX ( FILTER ( _ADDSORT, [Sort] <= EARLIER ( [Sort] ) ), [Sum] ) ) RETURN SUMX ( FILTER ( _RUNNINGTOTAL, [Category] = MAX ( 'Table'[Category] ) ), [Running Total] )Result is as below.
Best Regards,
Rico ZhouIf this post helps, then please consider Accept it as the solution to help the other members find it more quickly.