Forum Discussion
DAX for calculating previous month values
- Anonymous3 years ago
Hi Rosh89 ,
You could add a date column like below:
date = DATEVALUE("1-"&'Table'[Month])Then create a measure:
Measure = CALCULATE(SUM('Table'[Bonus]),FILTER(ALLEXCEPT('Table','Table'[Customer]),'Table'[date]=EDATE(SELECTEDVALUE('Table'[date]),-1)))
bsheffer In this table month is a text. I tried what you mentioned about using date as first of every month but it does not work that way because you need a calendar table marked as a date table with continous dates without any gap. Without a calendar table containing continous dates the date functions dont work.
if you want to use the calendar table (which doesn't have to be marked as a date table), you can use many available code snippets to create it.
Then you have to create a column in your fact table that converts your month, year field [Month] into a date (which is why I suggested date(yyyy, mm, 01) where yyyy is like right('fact'[month], 4) and mm is probably a switch statement).
That date can be linked to the calender table and now you can use all the date functions like adddate() on that table to get your monthly totals for whatever month range you want.