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
salman_ali
Helper IV
Helper IV

using Switch to compare column values

Hi this is what I have so far

BalanceScore = IF(AND([Shift1]=[Shift2],[Shift3]=[Shift4]),IF(AND([Shift3]=[Shift4],[Shift4]=[Shift5]),3,1),1)
 
I would like to setup a Dax forumula.  My table name is 'Math'
 
what I want to see is when the values of all the columns are the same, values returned should be 3, otherwise 1. 
 
I think I ought to use SWITCH(TRUE(), however I can't  use it properly
1 ACCEPTED SOLUTION
az38
Community Champion
Community Champion

Hi @salman_ali 

try

BalanceScore = IF(
'Math'[Shift1]='Math'[Shift2] && 'Math'[Shift2]='Math'[Shift3] && 'Math'[Shift3]='Math'[Shift4] && 'Math'[Shift4]='Math'[Shift5],
3,
1)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

5 REPLIES 5
V-pazhen-msft
Community Support
Community Support

@salman_ali 

You can use && instead of AND().

 

BalanceScore = Switch( True(), 
[Shift1]=[Shift2] && [Shift1]=[Shift3] && [Shift1]=[Shift4] && [Shift1]=[Shift5]) , 3,
1)

 

But It is not necessary to use Switch, you use switch when you want more 2 results.

 

BalanceScore = IF([Shift1]=[Shift2] && [Shift1]=[Shift3] && [Shift1]=[Shift4] && [Shift1]=[Shift5]), 3 ,1)

 

 

How to use Swtich: https://docs.microsoft.com/en-us/dax/switch-function-dax

 

Paul Zheng _ Community Support Team
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

edhans
Super User
Super User

Try this

BalanceScore =
SWITCH(
    TRUE(),
    AND(
        [Shift3] = [Shift4],
        [Shift4] = [Shift5]
    ), 3,
    AND(
        [Shift1] = [Shift2],
        [Shift3] = [Shift4]
    ), 1,
    1
)

 



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
az38
Community Champion
Community Champion

Hi @salman_ali 

try

BalanceScore = IF(
'Math'[Shift1]='Math'[Shift2] && 'Math'[Shift2]='Math'[Shift3] && 'Math'[Shift3]='Math'[Shift4] && 'Math'[Shift4]='Math'[Shift5],
3,
1)

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

Thank you, it worked!

Thanks, worked!

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.