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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
stsmith67
Frequent Visitor

Change Table Columns Based on Slicer Selection

Hi All,

 

I'm looking for a way to switch out columns in a table if a selection from a slicer is made.

Example
Year Slicer = 2021, show Columns A, B and C in my table or if
Year Slicer = 2022, show Columns A, B, D, G or if

Year Slicer = 2023, show Columns A, D, E, etc,

 

Has anyone found a way to do this while trying to use the same table and not have to resort to bookmarks using stacked tables?  Thanks.

6 REPLIES 6
Sultanista
Frequent Visitor

Try this one 
https://www.youtube.com/watch?v=CHGmuzxu_BE (in the description there is a link to 1st video that might be needed to continue with this one)

MarkBattista
Regular Visitor

Is there a way to change within the select statement? For example, select if 1=1 then column A vs B , column 2, if x=y then C vs D, column 4???  

 

 

 

 

 

 

Sahir_Maharaj
Super User
Super User

Hello @stsmith67,

 

You can achieve this using the "Switch" function in DAX:

 

Selected Columns = 
SWITCH (
    SELECTEDVALUE ( 'Year'[Year] ),
    2021, SELECTCOLUMNS ( Table, "A", [A], "B", [B], "C", [C] ),
    2022, SELECTCOLUMNS ( Table, "A", [A], "B", [B], "D", [D], "G", [G] ),
    2023, SELECTCOLUMNS ( Table, "A", [A], "D", [D], "E", [E] ),
    BLANK()
)

Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

I tried that and it looked like it was going to work, but then I get this error message.

 

The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.

The "Switch" function checks the selected value of the slicer and returns the appropriate set of columns using the "SelectColumns" function. If no value is selected in the slicer, the formula returns BLANK().

 

You can then use the "Selected Columns" measure in your table visualization instead of selecting the columns directly. When you change the value in the slicer, the columns displayed in the table will update automatically based on the selected year.

 

Let me know if you might need further guidance.


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning

Hi, 

 

I also am trying to do this and got the same error as above about the multiple values not being converted to scalar value. Your response explained how it works but didn't really answer why this error would occur. Do you know why we would be getting this error?

 

Thanks!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.