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 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
Thank you @BA_Pete !!
I manage to solve most of the issues by adding that column
Regards 🙂
Auxilio99357