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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.