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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
vshevch
New Member

OR() function

Hi,

 

I am using CALCULATE function to extract sum out of a column if it matches 1 out of 5 criteria. I used an OR() function to see if it matches any of those values. However, since DAX OR() function supports only 2 values, as opposed to excel OR() function, which supports multiple values, I had to make a nested OR statement - i.e. OR(OR(OR(value 1, value 2),OR(value 3, value 4),value 5). I was curious, is there a better way of doing this? Perhaps there is a more suitable function for this problem?

5 REPLIES 5
nickchobotar
Skilled Sharer
Skilled Sharer

Hello @vshevch

 

Yes there is a better way than nesting OR()s.  In my opinion, the easiest way to return your logic is to use the IN() operator which really simplifies the logical condtions.

I would write this measure like so:

 

= 
CALCULATE(
	<expression>, 
	'Current Champ Year and Month'[Current Champ Month] IN {3,6,9,12 }
)


Talking about IN() operator I think it's also good to mention its best friend CONTAINSROW() function.

You can re-write the measure above with CONTAINSROW() like so:

=
CALCULATE (
    <expression>,
    CONTAINSROW (
        {
            3,
            6,
            9,
            12 },
        'Current Champ Year and Month'[Current Champ Month]
    )
)


Thanks, Nick -

TheOckieMofo
Resolver II
Resolver II

I would get familiar with the SWITCH() function. It is very, very useful in situations like this. The basic syntax is:

 

Switch(expression,value1,result1,[value2],[result2],...[else])

 

Honestly, I've used this function so often that I probably have to have a conversation about it with my wife. We are really close. But let me break it down a little bit for you. The expression part of the function could be either a single column OR the dax function TRUE(). When using the second option, it opens up a world of awesome as described here on Collie's site: PowerPivotPro Switch TRUE. It allows you to do all sorts of things, including using multiple columns for conditional/logical analysis.

 

So, my point with all this (I promise there is one) is that the Switch function will work for you as it already applies a logical OR around each item in the list and it also gives you a catch "else" statement which you can use to lump all the cats and dogs together. Additionally, mastering the Switch TRUE combo will definitely come in handy down the road as you build more and more data models.

MattAllington
Community Champion
Community Champion

 

A generally better alternative than nested OR statements (in my view) is to use the double pipe symbol (above the enter key with the shift button).  With the double pipe, you can write  X = 1 || 2 || 3 || 5    This is semantically equivelant of =OR(1,2,3,5) in Excel

 



* 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.

Wouldn't it have to be X=1 || X=2 || X=3 || X=5?

 

Here's my example that worked:

Is Payout? = If('Current Champ Year and Month'[Current Champ Month] = 3 || 'Current Champ Year and Month'[Current Champ Month] =  6 || 'Current Champ Year and Month'[Current Champ Month] = 9 || 'Current Champ Year and Month'[Current Champ Month] = 12, "Yes", "No")

 

When I tried the following, it did NOT work:

Is Payout? = If('Current Champ Year and Month'[Current Champ Month] = 3 || 6 || 9 || 12, "Yes", "No")

Greg_Deckler
Community Champion
Community Champion

I'm thinking maybe SWITCH, but can you post your full formula so that I can see how you are using OR?

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Top Solution Authors