Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
KMZ_ESS
Helper I
Helper I

Measure with multiple filters on same field

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.

_Measure Customer Accounts =
CALCULATE(
count(Account[Account Number]),
FILTER(
Account[Status]= "Active",
Account[Relationship Type] = "Customer" &&
Account[Relationship Type] = "" &&
Account[Relationship Type] = "Non Buying Entity"
))
 
I've also tried:
CALCULATE (
SUM (Account[Account Number]),
FILTER (
Account[Relationship Type] in { "Customer","","Non Buying Entity"}
))
 
What am I doing wrong?
Also, I will need some more measures where more than 2 fields have to be filtered. Is that possible? I seem to recall the FILTER function can only handle 2 arguments.
Lastly, I would like to have the relative date filter (see screenshot) in a measure. How can I do that?
2023-04-13 17_01_53-Sales Rep Report draft MX - Power BI Desktop.png
 
Many thanks! 🙂
1 ACCEPTED 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 () ) )

View solution in original post

3 REPLIES 3
johnt75
Super User
Super User

Try

_Measure Customer Accounts =
CALCULATE (
    COUNTROWS ( Account ),
    Account[Status] = "Active",
    Account[Relationship Type] IN { "Customer", BLANK (), "Non buying entity" }
)

Perfect, that works! Thanks a lot for the fast response! 🙂

Would you have some advice on the other questions I added later, too? ->

Also, I will need some more measures where more than 2 fields have to be filtered. Is that possible? I seem to recall the FILTER function can only handle 2 arguments.
Lastly, I would like to have the relative date filter (see screenshot) in a measure. How can I do that?
Thanks in any case! 🙂
2023-04-13 17_01_53-Sales Rep Report draft MX - Power BI Desktop.png

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 () ) )

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.