Forum Discussion
how does filter context work
- 4 years ago
Hi, Jeanxyz
The same logic is difficult to reproduce in a general dax formula( without considering the number of days), which has been mentioned in 'The Definitive Guide to DAX'.
The following formula is similar, but not completely equivalent.
TREATAS( SELECTCOLUMNS( CALCULATETABLE(DISTINCT('Date'[Date])), "Date",DATE( YEAR('Date'[Date]), MONTH('Date'[Date])-1, DAY('Date'[Date]) ) ), 'Date'[Date]))This formula will work normally only when the target month and the current month have the same number of days, otherwise several days(1day=31-30, 2days=29-31,3days=28-31 ) will be lost or included.
Best Regards,
Community Support Team _ Eason
Hi, Jeanxyz
The same logic is difficult to reproduce in a general dax formula( without considering the number of days), which has been mentioned in 'The Definitive Guide to DAX'.
The following formula is similar, but not completely equivalent.
TREATAS(
SELECTCOLUMNS(
CALCULATETABLE(DISTINCT('Date'[Date])),
"Date",DATE(
YEAR('Date'[Date]),
MONTH('Date'[Date])-1,
DAY('Date'[Date])
)
),
'Date'[Date]))
This formula will work normally only when the target month and the current month have the same number of days, otherwise several days(1day=31-30, 2days=29-31,3days=28-31 ) will be lost or included.
Best Regards,
Community Support Team _ Eason