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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Anonymous
Not applicable

Switch statement to return chat values

hello all,

 

i have this sample data in Power BI:

 

UsersSalesmembersManagersCarsPhonesExpensespagers
10,2051,5005002,0002,0001,5031,500

 

What I am trying to create is a chart like this:

Picture1.png

 

What I have done is created a disconnected table with all the categories and placed that measure in the axis.

Category
Users
Salesmembers
Managers
Cars
Phones
Expenses
pagers

Now I need to use a DAX meaure to place in the visual to return the correct values.

 

how can I do this with DAX? 

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

yes! thank you so much

View solution in original post

One thing, for you to display the CATEGORY level - managers, cats etc etc on the X axis, DAX would need a table that contains those values in a single column.

 

You can either achieve it by creating a table on-the-fly like I did and have the visual created form table 2 or by creating a disconnected table as DCN in the example and then SWITCH !!!! 😂😂

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

View solution in original post

15 REPLIES 15
smpa01
Super User
Super User

I am not sure whether you wanted PBI to render the chart or want a switch statement. PowerBI can return the same chart without needing a switch at all.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

the reason I wanted to use a switch statement is because I have a lot of other data in my file and I dont want to mess up any other visuals if I were to pivot this data

Does this work for you?

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

@smpa01  I spoke too soon:

 

is it possilbe to use a switch statement when the data is formatted like this:

 

UsersSalesmembersManagersCarsPhonesExpensespagers
10,2051,5005002,0002,0001,5031,500

 

not pivoted 

As long as the categories in the source data are within a single column the measure will work as planned even if you plan to include those categories as columns in the viz.

 

But if the categories are separate columns within the source data, they need to be pivoted first to cluster in a single column for you to achieve what you need.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

got it. My last question would be is it possible to create a seprate table pulling in only the data i need from the origional table? 

 

meaning only pulling this data:

 

UsersSalesmembersManagersCarsPhonesExpensespagers
10,2051,5005002,0002,0001,5031,500

 

into a new table so I can pivot

 

thank you so much for the help

@Anonymous  can you please provide me a source data which would have other undesired data and the final output that you desire.

 

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

Sure one moment. How can I add a file to this thread ? I dont see where I can drop a file

you can share a file through G/1 drive

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

here is the pbix file with the sample data. https://drive.google.com/open?id=1W6IiXgXpEGylUPt-bUIln7uakSDb_Ax6

 

I cannot pivot the data because i am using the other data for other visuals.

 

this is what I would like to accomplish :

 

Picture1.png

 

 

One thing, for you to display the CATEGORY level - managers, cats etc etc on the X axis, DAX would need a table that contains those values in a single column.

 

You can either achieve it by creating a table on-the-fly like I did and have the visual created form table 2 or by creating a disconnected table as DCN in the example and then SWITCH !!!! 😂😂

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

@smpa01  is it possible to only sumarize the most current date and not all the dates?

yes possible

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
Anonymous
Not applicable

thank you, this is perfect 

Anonymous
Not applicable

yes! thank you so much

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.