Forum Discussion
DAX: How to perform a cummulative summation
- 10 years ago
First you need to have a seperate date table in order to perfom date calculations...
Step 1 : Create a date table -> Go to Modelling click New Table -> enter Dates = CALENDARAUTO()..Now you have a date table call Dates..-> New Column in this table Month = MONTH(Dates[Date])
Step 2 : Create Relantionship between your yourtable[Dates] ( the new only dates you created ) and Dates[Date] ( the calculated table)
Step 3 : Rewrite your formula to Measure = CALCULATE(
SUM(rprtsolarhistorical[Daily Output]);
FILTER(
ALL(Dates[Dates]);
Dates[Date]) <= MAX(Dates[Date])
)
)Step 4: add the months field from the new Dates table and the "measure"
Hope this works
Hi Haegi
Thanks for the help. I can create the measure with no errors but cannot then bring it into any table or graph??
Get an error
"MdxScript(Model) (2, 43) Calculation error in measure 'InvoiceDetail'[CumulativeYear]: The function MAX takes an argument that evaluates to numbers or dates and cannot work with values of type String."
My code is.
CumulativeYear = CALCULATE(SUM(InvoiceDetail[DETAIL_KMS_TOCHARGE]), FILTER(ALL(Dates[Year]),Dates[Year] = MAX(Dates[Year])), FILTER(ALL(Dates[MonthName]),Dates[MonthName] <= MAX(Dates[MonthName])))
Same result if I remove out the Month filters and just have one on the years.
Good job!
This error explain that MAX function doesnt work with String value.
I suppose the column 'MonthName' is a string like "January" or "Febuary", we must instead use integer value like 1,2,3,4,5 etc..
for the Month column.
Regards.