Forum Discussion
DAX Query - Temp Table Filter Measure - Previous Year Sum
Hi Community Support Team _ Jing
Yes we experienced the same leap year issue in our org and its a pain for this reason. We have a calendar table that is updated regularly with Flags to specify which week we are in marked as a 1, We do this for the same week last year (Flag marked as 2) and 2 years ago (Flag Marked as 3) for each row in the calendar table by day.
So I made use of this with the following dax.
var shortdayToday =
CALCULATE(
DISTINCT('Calendar'[Short Day Name]),
'Calendar'[date] = TODAY()
)
var DateToday =
CALCULATE(
DISTINCT('Calendar'[date]),
'Calendar'[date] = TODAY()
)
var DateLY =
CALCULATE(
DISTINCT('Calendar'[date]),
FILTER('Calendar','Calendar'[LYInWeekFlag] = 2),
FILTER('Calendar','Calendar'[Short Day Name] = shortdayToday)
)
RETURN
CALCULATE (
SUM ( 'Sales - Hourly'[Sale Value] ),
FILTER('Calendar','Calendar'[Short Day Name] = shortdayToday),
FILTER('Calendar','Calendar'[Date] = DateLY),
'Time'[Up To Hour] = 1
)I wanted to make use of DAX Define table which would shorten the code but couldnt use in pbi or aas measure definition so had to make do with variables. While this supports my problem it would be easier if there was a function that we could use for same day LY.
Hi Mark_Timson
It seems your current dax could be shortened into below as DateToday variable is never used in the following part and if 'Calendar'[date] is unique in Calendar table.
var shortdayToday =
CALCULATE(
DISTINCT('Calendar'[Short Day Name]),
'Calendar'[date] = TODAY()
)
var DateLY =
CALCULATE(
DISTINCT('Calendar'[date]),
FILTER('Calendar','Calendar'[LYInWeekFlag] = 2),
FILTER('Calendar','Calendar'[Short Day Name] = shortdayToday)
)
RETURN
CALCULATE (
SUM ( 'Sales - Hourly'[Sale Value] ),
FILTER('Calendar','Calendar'[Date] = DateLY),
'Time'[Up To Hour] = 1
)
Regards,
Jing