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
KrisD
Helper II
Helper II

Switch function does not accept any of my attempts

Hi!

 

I've searched far and wide to find an answer and it feels like I've tried every possible combination I can think of, but have come up short so this is my last refuge. 

I have a table with 3 columns. The first is text, the second is integer and the third is a switch measure intended to produce a value for each of the rows based on the first column or the second depending on switching with text or integer. 

 

If I switch based on text in col 1 and the result is text I get the usual "can't compare text with true/false. 

If I switch based on integer in col 2 and the result is integer I get the usual "can't compare integer with true/false. 

If I switch with "if rank = 12, then 1 (all simple integers) I get an error and so on and so on...

The image below is just one of 100 combinations I've tried so you can see what I'm working with. 

 

KrisD_0-1623394651333.png

What is the correct way of solving this? 

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@KrisD , There two way you use switch

 

Switch( selectedvalues([column]) ,

"11", "Abc",

"12", "DEF"

)

 

 

Switch( true() ,

selectedvalues([column]) = "11", "Abc",

selectedvalues([column]) = "12", "DEF"

)

 

refer my video

Switch-Case statement of #PowerBI: https://www.youtube.com/watch?v=gelJWktlR80&list=PLPaNVDMhUXGaaqV92SBD5X2hk3TMNlHhb&index=56

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

Fowmy
Super User
Super User

@KrisD 

Since you have conditions inside SWITCH, modify your formula as follows.
Replace SELECTEDVALUE ( 'Sammanstalling (2)' [Rank] ) with TRUE()

SWITCH ( TRUE() ,
    'Sammanstalling (2)' [Rank] = 12 , [Gra..




Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

6 REPLIES 6
KrisD
Helper II
Helper II

Hi, I don't understand. Suddenly the code works and I have no idea why. 

Thanks for your input guys! I will accept both your suggestions as solution. 

Fowmy
Super User
Super User

@KrisD 

Since you have conditions inside SWITCH, modify your formula as follows.
Replace SELECTEDVALUE ( 'Sammanstalling (2)' [Rank] ) with TRUE()

SWITCH ( TRUE() ,
    'Sammanstalling (2)' [Rank] = 12 , [Gra..




Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

@KrisD 

I would suggest you create some sample data in Excel with expected results in the column and share it here so a correct solution can be found.

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Hi! 
I can't use TRUE since I need to produce a number for each row (every value in col 1) and TRUE will stop comparing after the first true result. 

amitchandak
Super User
Super User

@KrisD , There two way you use switch

 

Switch( selectedvalues([column]) ,

"11", "Abc",

"12", "DEF"

)

 

 

Switch( true() ,

selectedvalues([column]) = "11", "Abc",

selectedvalues([column]) = "12", "DEF"

)

 

refer my video

Switch-Case statement of #PowerBI: https://www.youtube.com/watch?v=gelJWktlR80&list=PLPaNVDMhUXGaaqV92SBD5X2hk3TMNlHhb&index=56

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi!

 

Hi! 
I can't use TRUE since I need to produce a number for each row (every value in col 1) and TRUE will stop comparing after the first true result.

The result in col 3 needs to be a number produced from my measure. 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors