Forum Discussion
Running Total
- 10 years ago
Eyy, I think I got it. Try this:
RunningTotal2 = MAXX(Table1, SUMX( FILTER( SUMMARIZE(CALCULATETABLE(Table1, ALLEXCEPT(Table1, Table1[Building]), ALLSELECTED(Table1[Building])), Table1[MachineName], "NetVal", SUM(Table1[Fabrication Net Value])), [NetVal] >= SUMX(FILTER(CALCULATETABLE(Table1, ALLEXCEPT(Table1, Table1[Building]), ALLSELECTED(Table1[Building])), Table1[MachineName]= EARLIER(Table1[MachineName], 2)), Table1[Fabrication Net Value])) , [NetVal]))
Hopefully you can see how that would scale out to other columns if you had multiple filters.
Where would the running total start, and what would be the next value added to the total?
- Lucy6410 years agoAdvocate II
I would sort the list in descending order of Fabrication Net Value and it would start with the first row and continue adding each row. Here is the result I am looking for.
Machine Name Fabrication Net Value Running Total Rollpacks 16752 16752 Tightwinder 12390 29142 T8 ( 2 ) 10217 39359 T8 ( 4 ) 5821 45180 Cut off saw 5801 50981 T8 ( 3 ) 2509 53490 T8 (1 ) 2155 55645 Tarp saw 568 56213 C52 Pillow Machine 309 56522 Bun Roller Machine 229 56751 Chinese Carousel 124 56875 - Habib10 years agoContinued Contributor
To achieve this you need to add some order number to you machines for DAX to identify how it should calculate running total. In your example i have added SrNo column and gave sequence values to this. Next I added a new column with below formula and it gave me desired results....
Another idea other than SrNo is to use the row number based on sorted column of your choice
RunningTotal = CALCULATE(SUM(Machine[Fabrication Net Value]),all(Machine),Machine[SrNo]<=EARLIER(Machine[SrNo]))
Below is the output
- joglidden10 years agoAdvocate III
But what if the order changes, because of the magnitude of Fabrication Net Value? I.e., Tightwinder outperforms Rollpacks... maybe that will still work. The best example I've found so far is here:
http://www.daxpatterns.com/cumulative-total/
But the problem is that this example uses dates.