Forum Discussion
andybamber
Helper III
6 years agoHelp with PREVIOUSMONTH
Hello! I'm hoping someone could help me with a query regarding the PREVIOUSMONTH function. I have a fact table containing a column of sales figures, the same table also contains a period key... i...
TomMartens
Super User
6 years agoHey andybamber ,
there is a quite short answer to your question: You can't.
PREVIOUSMONTH as most of the other time intelligence functions requires a dedicated date table without gaps.
You might consider using the following approach:
- Get the current date var _currentDate = MAX('periodtable'[date])
- Get the endofmonth of the previous month _eomPrevMonth = EOMONTH(_currentDate , -1)
- Now get the start of the previous month var _startOfPrevMonth = DATE(YEAR(_eomPrevMonth) , MONTH(_eomPrevMonth) , 1)
You can use the variable to filter your period table like so by creating a measure like so:
measure =
var _currentdate = ...
var _eomPrevMonth = ...
var _startOfPrevMonth = ...
return
CALCULATE(
<your numeric expression>
, 'periodtable'[date] = _startOfPrevMonth
)
Hopefully, this provides an idea on how to tackle your challenge.
Regards,
Tom