Forum Discussion
Measure with multiple filters on same field
- 3 years ago
FILTER can handle multiple conditions as long as they are on the same table, you just need to join them with && for and and || for or conditions.
If you are using them inside a CALCULATE statement then you don't need to explicitly specify FILTER, you can pass in as many filter conditions as you like and they can be across multiple tables.
For the relative date filter, if you have a proper date table set up you could use something like
Within last 3 months = VAR StartDate = EOMONTH ( TODAY (), -4 ) + 1 RETURN CALCULATE ( [My measure], DATESBETWEEN ( 'Date'[Date], StartDate, TODAY () ) )
The code you posted won't work for a couple of reasons. The first argument to FILTER needs to be a table, not a filter condition. Secondly you are trying to place two filters on the [Relationship Type] column using an AND condition - the column cannot have both values at the same time.
If you want to use my original solution but have it react to slicers as well you can wrap either or both of the filter condition lines in KEEPFILTERS. That way it will intersect the filters specified in the measure with filters from slicers, rather than overwriting them.
I understand why my version of code don't work. Mneahwile, I ain't able to visualize the code you mentioned to react to slicer. Do you mind typing out the code and explain the change?
- johnt751 year agoSuper User
_Measure Customer Accounts = CALCULATE ( COUNTROWS ( Account ), KEEPFILTERS( Account[Status] = "Active" ), KEEPFILTERS( Account[Relationship Type] IN { "Customer", BLANK (), "Non buying entity" } ) )The KEEPFILTERS tells Power BI to use the filters specified as well as any filters or slicers you apply externally. Without the KEEPFILTERS the filters specified in the measure will ignore any external filters.