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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
PBI_Carousel_NL_June

Fabric Community Update - June 2024

Get the latest Fabric updates from Build 2024, key Skills Challenge voucher deadlines, top blogs, forum posts, and product ideas.

Top Solution Authors