Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
Dear all,
I'm trying to create a measure to show the number of accounts that have the following attributes:
- Status: active
- Relationship Type: Customer, (blank), Non Buying Entity
I used this measure but I get an error.
Solved! Go to Solution.
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 () ) )
Try
_Measure Customer Accounts =
CALCULATE (
COUNTROWS ( Account ),
Account[Status] = "Active",
Account[Relationship Type] IN { "Customer", BLANK (), "Non buying entity" }
)
What's the difference between following code and one above, if you can please provide technical answer:
_Measure Customer Accounts =
CALCULATE (
COUNTROWS ( Account ),
FILTER(Account[Status] = "Active" && Account[Relationship Type]="Customer"&& Account[Relationship Type]="Non buying entity"))
I did face similar problem as described but was able to fix with your code. But i ran into another problem, the measure value in card is not changing when selecting Non buying entity in slicer settings with your code. What could be problem?
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?
_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.
Perfect, that works! Thanks a lot for the fast response! 🙂
Would you have some advice on the other questions I added later, too? ->
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 () ) )
User | Count |
---|---|
141 | |
70 | |
70 | |
53 | |
52 |
User | Count |
---|---|
208 | |
94 | |
64 | |
60 | |
57 |