I need to return previous month's value (Year-To-Date) based on date picker, however, I don't want to return it if it's December previous year. Example. it's Januray 2023 and I don't want to return value for December 2022. I tried with this measure but it just doesn't do anything:
VAR vLastMonth =
CALCULATE(
EOMONTH(MAX( DateTable[Date] ),-1),
ALLSELECTED( DateTable[Date] )
)
RETURN
CALCULATE(
TOTALYTD(
SELECTEDMEASURE(),
'DateTable'[Date]
),
FILTER(
ALL('DateTable'),
'DateTable'[Month] = MONTH(vLastMonth)
&&
'DateTable'[Year] = YEAR(vLastMonth)
)
)
vLastMonth measure works fine and return end of previous month. Rest of the code doesn't throw an error but it also not work properly at all, still takes values from December:
screenshot of my table not working as expected
How can I fix it in my code?
How about just checking if the month in question is December and if so, returning 0 instead of the previous month?
VAR vLastMonth =
CALCULATE(
EOMONTH(MAX(DateTable[Date]), -1),
ALLSELECTED(DateTable[Date])
)
RETURN
IF(
MONTH(vLastMonth) = 12,
BLANK(), // Return 0 instead if you'd like
CALCULATE( // Rest of your measure goes here