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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
harib
Post Patron
Post Patron

How to create switch statement in columns

Hi

I would like to create below switch statement using column. I have tried, but it's not showing the values. If it's possible please let me know

 

SWITCH(
TRUE(),
SELECTEDVALUE(Columns_names[Query1])="A",FIRSTNONBLANK(Orders[A],1),
SELECTEDVALUE(Columns_names[Query1])="B",FIRSTNONBLANK(Orders[B],1),
SELECTEDVALUE(Columns_names[Query1])="C",FIRSTNONBLANK(Orders[C],1),
"Nothing")

 

Thanks in advance

5 REPLIES 5
Greg_Deckler
Super User
Super User

I have a suspicion that you are likely not using SELECTEDVALUE correctly but that is really hard to say without context. If you are trying to do this in a calculated column for example, I would not use SELECTEDVALUE in that case, I would just use the column name. Also, using SWITCH TRUE here technically does not make sense, just use the standard form of SWITCH. So you might try:

 

 

Column = 
  SWITCH(
    [Query1],
    "A",FIRSTNONBLANK(Orders[A],1),
    "B",FIRSTNONBLANK(Orders[A],1),
    "C",FIRSTNONBLANK(Orders[A],1),
    "Nothing"
  )

 

 

If this is a measure, I would try this:

 

 

Measure = 
  SWITCH(
    MAX('Columns_names'[Query1]),
    "A",FIRSTNONBLANK(Orders[A],1),
    "B",FIRSTNONBLANK(Orders[A],1),
    "C",FIRSTNONBLANK(Orders[A],1),
    "Nothing"
  )

 



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

@amitchandak 

@Greg_Deckler 

 

From the below Actual output if we select any value from Input_Groups, it's reflecting the same in the table visual, let's say if i select All, it will appeare in the table , same other values also.

6.PNG

 

But my requirement is if i dont select any values from Input_Groups it has to come like below output with aggerated values else by default it has to display "ALL".  With All we can see aggregated values. 

 

Usevally what i was doing, by default selecting the "All" values and deploying into the services. But if user remove the filter from the Input_Groups it will give all detailes values and aggreageted values will split . 

7.PNG

Sample File: https://drive.google.com/file/d/1I4iiRDKf-H9vQ0vU4BTtGpn-Ey0YeiT/view?usp=sharing

 

If it's possible please let me know. 

Thanks in advance

After looking at your PBIX it strikes me that you might possibly want to unpivot your three columns to obtain a single column and then things will be easier. I would try this, but I do not have your Sample.xlsx file so I cannot test this out. But, I'm pretty sure that unpivoting would pretty much make this a cake walk.



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!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 

 

I have attached xlsx file. could u pleaase check and lt me know the solutions. 

 

Sample PBIX : https://drive.google.com/file/d/1I4iiRDKf-H9vQ0vU4BTtGp-Ey0YehiT/view?usp=sharing

 

Sample.xlsx file : https://drive.google.com/file/d/1brZTsnfqx0mTryREYkTrb5PreaC5mO8a/view?usp=sharing

 

Regards,

Hari

amitchandak
Super User
Super User

When you this calculation in measure context is very important. Can you share sample data and sample output.

 

In between try

var _max = maxx(Columns_names,SELECTEDVALUE(Columns_names[Query1]))
SWITCH(
TRUE(),
_max="A",FIRSTNONBLANK(Orders[A],1),
_max="B",FIRSTNONBLANK(Orders[B],1),
_max="C",FIRSTNONBLANK(Orders[C],1),
"Nothing")
Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

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.