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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
SJ25
Resolver I
Resolver I

Using multiple value filters in Calculate

Hello All,

 

I'm trying to calculate total hours for only certain part numbers. I'm trying to filter them using calculate as below:

 

Reqhrs = Calculate ([Total Hours], New[Part Numbers] = 1111 && 11111)

 

I'm getting the desired result if I filter for just 1 part number but if I enter 2 or more, the result is blank.

 

Any help would be appreciated. Thanks

2 ACCEPTED SOLUTIONS
MattAllington
Community Champion
Community Champion

You are using "and" but you should be using "or". Any given product can't be part number 1111 and also be part number 11111


Here are two options

 

Reqhrs = Calculate ([Total Hours], New[Part Numbers] = 1111 || 11111)

 

Reqhrs = Calculate ([Total Hours], New[Part Numbers] in {1111,11111})

 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

View solution in original post

The correct syntax is:

Reqhrs = Calculate ([Total Hours], New[Part Numbers] = 1111 || New[Part Numbers] = 11111)

But CALCULATE has a limit on how many boolean filters you can do. You should consider using filter. Much more flexible, and this is what DAX is doing in the background anyway.

Reqhrs =
CALCULATE (
    [Total Hours],
    FILTER (
        New,
        New[Part Numbers] = 1111
            || New[Part Numbers] = 11111
    )
)

FILTER will let you filter fields from multiple tables. You cannot do that in CALCULATE without FILTER(). DAX isn't smart enough to translate your boolean logic to include multiple tables.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

3 REPLIES 3
MattAllington
Community Champion
Community Champion

You are using "and" but you should be using "or". Any given product can't be part number 1111 and also be part number 11111


Here are two options

 

Reqhrs = Calculate ([Total Hours], New[Part Numbers] = 1111 || 11111)

 

Reqhrs = Calculate ([Total Hours], New[Part Numbers] in {1111,11111})

 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

@MattAllington Thanks for your reply. Using the two options you mentioned above is giving me two different results. The first option is giving me the total for all part numbers, the second one seems to be accurate. Upon looking more, is it possible that to use the first option I'll have to repeat the table name after every OR ( || ) sign?

The correct syntax is:

Reqhrs = Calculate ([Total Hours], New[Part Numbers] = 1111 || New[Part Numbers] = 11111)

But CALCULATE has a limit on how many boolean filters you can do. You should consider using filter. Much more flexible, and this is what DAX is doing in the background anyway.

Reqhrs =
CALCULATE (
    [Total Hours],
    FILTER (
        New,
        New[Part Numbers] = 1111
            || New[Part Numbers] = 11111
    )
)

FILTER will let you filter fields from multiple tables. You cannot do that in CALCULATE without FILTER(). DAX isn't smart enough to translate your boolean logic to include multiple tables.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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