Forum Discussion
SAMEPERIODLASTYEAR()
- 5 years ago
Hi auxilio99357 ,
The previous code I supplied for DAX and Power Query M were both intended to be new columns in your calendar table, not measures.
For your specific scenario i.e. sales only go up to two months ago, I would recommend adding a relative month column into your calendar table, something like this:
DAX
_relativeMonth = (YEAR(DimDates[Date]) * 12 + MONTH(DimDates[Date])) - (YEAR(TODAY()) * 12 + MONTH(TODAY()))PQ M
(Date.Year([Date]) * 12 + Date.Month([Date])) - (Date.Year(DateTime.LocalNow()) * 12 + Date.Month(DateTime.LocalNow()))The usage of this in a measure would look something like this:
LYTD = CALCULATE( SUM(Sales[U_Liq]), SAMEPERIODLASTYEAR(DimDates[Date]), DimDates[relativeMonth] <= -2 )Pete
Hi, @BA_Pete !!
When trying to add the field I think I understood why all the time intelligent measures don´t work as I expect. My Sales table will always contain the value of sales up to two months before the current day.
So now I want to create a 'CurrentDay' with the condition that the current day is two months from the actual current day.
To do that I'm trying to adapt the 'CurrentDay' field you specified.
First I wanted to create the field exactly as you wrote it by adding a new measure to the DimDates table and by adding a new table. In both times, when when I wrote the code, I couldn´t write "DimDates[Date]" after the IF funtion.
Is this correct or did I misunderstand?
Thank you
😊
Hi auxilio99357 ,
The previous code I supplied for DAX and Power Query M were both intended to be new columns in your calendar table, not measures.
For your specific scenario i.e. sales only go up to two months ago, I would recommend adding a relative month column into your calendar table, something like this:
DAX
_relativeMonth =
(YEAR(DimDates[Date]) * 12 + MONTH(DimDates[Date])) - (YEAR(TODAY()) * 12 + MONTH(TODAY()))
PQ M
(Date.Year([Date]) * 12 + Date.Month([Date])) - (Date.Year(DateTime.LocalNow()) * 12 + Date.Month(DateTime.LocalNow()))
The usage of this in a measure would look something like this:
LYTD =
CALCULATE(
SUM(Sales[U_Liq]),
SAMEPERIODLASTYEAR(DimDates[Date]),
DimDates[relativeMonth] <= -2
)
Pete
- auxilio993575 years agoFrequent Visitor
Thank you @BA_Pete !!
I manage to solve most of the issues by adding that column
Regards 🙂
Auxilio99357