Forum Discussion
Anonymous
3 years agoNot applicable
Cumulative sum in a table
Hello all, I'm struggling to calculate a cumulative difference between two columns. My dataset is a table that, for each month of the year, reports two values: "Sum of Requested orders" and ...
- 3 years ago
Hi Anonymous
Please tryDifference = VAR CurrentMonth = MAX ( 'Date'[Month Number] ) VAR T1 = CALCULATETABLE ( VALUES ( 'Date'[Month] ), 'Date'[Month Number] <= CurrentMonth ) VAR T2 = ADDCOLUMNS ( T1, "@Difference", VAR CurrentMonth1 = 'Date'[Month] RETURN CALCULATE ( [Requested] - [Confirmed], ALL ( 'Date'[Month] ), 'Date'[Month] = CurrentMonth1 ) ) RETURN SUMX ( T2, [@Difference] )
Stachu
Community Champion
3 years agoThat looks like an output table, i.e. matrix visual.
What is your input data? If it looks like the table below then it's an easy setup
| Month | Requested | Confirmed |
| Jan | 2400 | 2300 |
| Feb | 1000 | 800 |
- Anonymous3 years agoNot applicable
hi Stachu
yes, table is as you reported. For each row I need to calculate the difference (Requested - Confirmed).
Moreover, I need that this difference is cumulative, so that each month difference is summed to the one calculated in the previous month
e.g.:
Jan = 2.400 - 2.300 = 100
Feb = (1.000 - 800) + January = 200 + 100 = 300
March = (xxx - xxx) + Feb = ( ... ) + 300