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 ,
If you don't ever want to see last year's sales ahead of where you are in the current year, then the easiest way to do this is by adding a [currentDay] field to your date dimension.
In DAX, it would be something like this:
currentDay =
IF(
calendar[date] < TODAY(),
"History",
"Future"
)
In Power Query M, it would be something like this:
currentDay =
if [date] < Date.From(DateTime.LocalNow()) then "History" else "Future"
You can then really easily filter pages, visuals, or even measures using this field to prevent 'future' dates from figuring into your report.
Pete