Forum Discussion
Filter function and Previous month
- 4 years ago
Hi Niclas,
The reason for this behaviour is:
- The 2nd argument of CALCULATE includes all columns of the (filtered) 'Export Data' table, which therefore includes the dates in the original filter context (the expanded 'Export Data' table includes the columns of DATES as well as all columns in 'Export Data').
- The 3rd argument of CALCULATE includes the dates in the previous month.
- Since the dates present in these two filter arguments don't intersect, the measure result is blank.
As a general principle, it's best to filter on specific columns, rather than tables. In this case, I would suggest filtering the ProductName column rather than the 'Export Data' table.
A measure like either of the below measures should return the expected result.
KEEPFILTERS can be used if you want the ProductName filter to intersect with existing ProductName filters.
(Note: I assumed that the only tables involved are Export Data and DATES. I'm assuming 'Export Data SE' was a typo(?) Also used IN operator.)
Fixed Measure = CALCULATE ( DISTINCTCOUNT ( 'Export Data'[OrderId] ), KEEPFILTERS ( 'Export Data'[ProductName] IN { "X", "Y" } ), PREVIOUSMONTH ( DATES[Date] ) )Fixed Measure = CALCULATE ( DISTINCTCOUNT ( 'Export Data'[OrderId] ), 'Export Data'[ProductName] IN { "X", "Y" }, PREVIOUSMONTH ( DATES[Date] ) )Regards,
Owen
Hi Niclas,
The reason for this behaviour is:
- The 2nd argument of CALCULATE includes all columns of the (filtered) 'Export Data' table, which therefore includes the dates in the original filter context (the expanded 'Export Data' table includes the columns of DATES as well as all columns in 'Export Data').
- The 3rd argument of CALCULATE includes the dates in the previous month.
- Since the dates present in these two filter arguments don't intersect, the measure result is blank.
As a general principle, it's best to filter on specific columns, rather than tables. In this case, I would suggest filtering the ProductName column rather than the 'Export Data' table.
A measure like either of the below measures should return the expected result.
KEEPFILTERS can be used if you want the ProductName filter to intersect with existing ProductName filters.
(Note: I assumed that the only tables involved are Export Data and DATES. I'm assuming 'Export Data SE' was a typo(?) Also used IN operator.)
Fixed Measure =
CALCULATE (
DISTINCTCOUNT ( 'Export Data'[OrderId] ),
KEEPFILTERS ( 'Export Data'[ProductName] IN { "X", "Y" } ),
PREVIOUSMONTH ( DATES[Date] )
)Fixed Measure =
CALCULATE (
DISTINCTCOUNT ( 'Export Data'[OrderId] ),
'Export Data'[ProductName] IN { "X", "Y" },
PREVIOUSMONTH ( DATES[Date] )
)
Regards,
Owen