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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
Anonymous
Not applicable

Custom slicer to select and display multiple columns

Hello,

 

I am trying to create a custom slicer based on multiple columns. Here is the data I have currently: 

aabbccdd 2020 A2020 B2020 C2021 A2021 B2021 C2022 A2022 B2022 C
a1b1c1d1Customer 1         
a2b2c2d2Customer 2         
a3b3c3d3Customer 3         

 

I want to create a slicer such that I can select one or multiple specific years. For example, if I select "2020" in the slicer, the output would look like this:

aabbccdd 2020 A2020 B2020 C
a1b1c1d1Customer 1   
a2b2c2d2Customer 2   
a3b3c3d3Customer 3   

 

How can I do this?

 

Really appreciate your help - thanks!

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

I updated my pbix file(see the attachment), please find the details in it.

vyiruanmsft_1-1721637643979.png

The below one is my answer of your above questions:

1. It has been achieved in my updated pbix file.

2 and 3: I'm sorry those two things can't be accomplished. Regarding your third question, you can add the latest year to the YEAR table to avoid that the latest year's data can't be rendered in table visual. 

vyiruanmsft_0-1721637499653.png

Using unpivot+matrix is the best solution to solve your three problems. (Years are multi-selected, unselected years are not shown in the visual, slicer options are from this table)

Best Regards

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

View solution in original post

8 REPLIES 8
danextian
Super User
Super User

Hi @Anonymous 

You need to unpivot all columns but customer so those column names go to the rows and then split or extract the year and category (ABC) from the unpivoted columns. Your data should something like below after the transformation:

danextian_0-1720671638953.png

Please see attached pbix for your reference.





Dane Belarmino | Microsoft MVP | Proud to be a Super User!

Did I answer your question? Mark my post as a solution!


"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
Anonymous
Not applicable

Thank you for your reply. I actually have more columns in addition to the Customer column that I would like to preserve (see below). Does the aforementioned method also work? I'm worried that it might be too messy.

 

aabbCustomerddee2020 A2020 B2020 C2021 A2021 B...
a1b1Customer 1d1e1     
a2b2Customer 2d2e2     
a3b3Customer 3d3e3     

 

Really appreciate your help - thank you!

@danextian Thanks for your contribution on this thread.

Hi @Anonymous ,

@danextian has provided the possible solution, here need to make a little adjustment: select the columns which include year info and only unpivot these selected columns in Power Query Editor. Please find the details in the attachment.

1. Only unpivot the columns which include year info

= Table.Unpivot(#"Changed Type", {"2020 A", "2020 B", "2020 C", "2021 A", "2021 B", "2021 C"}, "Attribute", "Value")

2. Create a Text filter and matrix visual with below settings 

vyiruanmsft_0-1721033666989.png

Best Regards

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

Hello @v-yiruan-msft ,

 

Thank you so much for your reply. I am experimenting with the method you just provided.

 

Due to user demand, the output visual has to be a table, instead of a matrix, which is why I expanded the columns as 2020A, 2020B, 2020C... earlier, instead of unpivoting them into a single Attribute column. 

 

Could you kindly help with this situation? Is there any way to overcome this roadblock? How could I modify your method to create a table output? Thank you.

Hi @Anonymous ,

If you can't unpivot these columns with the year inside the power query editor then they are multiple columns and not one. I have updated my pbix file(see the attachment), please check if it is what you want.

vyiruanmsft_0-1721123186717.png

Best Regards

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

Hi @v-yiruan-msft,

 

Thank you so much for your response. This is working great!

 

However, I have encountered 1 problem and 2 follow-up questions.

 

  1. The visual works perfect when I select a single year in the slicer, but it would not work when I multi-select. It could not display ALL years as well. For my data, I have 4 years that I would like to either display 1, multiple, or all years. Could you kindly help on this topic?
  2. Currently, when I select 2020 in the Year slicer, columns 2021 A, B, and C would be blank but still displayed. Is it possible to hide and not display the columns that weren't selected in the Year slicer?
  3. The table visual you created has columns aa, bb, cc... selected from "Table 2", and 2020A, 2020B, 2020C... selected from the "Year" table. Because I plan to refresh the Power BI dashboard weekly with new data pasted to the same excel file, is it possible to select 2020A, 2020B, 2020C... from "Table 2" instead of "Year"? How can I modify the current code for the slicer to still work?

 

Thank you. Really appreciate your help!

Hi @Anonymous ,

I updated my pbix file(see the attachment), please find the details in it.

vyiruanmsft_1-1721637643979.png

The below one is my answer of your above questions:

1. It has been achieved in my updated pbix file.

2 and 3: I'm sorry those two things can't be accomplished. Regarding your third question, you can add the latest year to the YEAR table to avoid that the latest year's data can't be rendered in table visual. 

vyiruanmsft_0-1721637499653.png

Using unpivot+matrix is the best solution to solve your three problems. (Years are multi-selected, unselected years are not shown in the visual, slicer options are from this table)

Best Regards

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

Hello @v-yiruan-msft,

 

Yes, this is looking great! Thank you so much for all the responses. Really appreciate it! 

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 FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors
Top Kudoed Authors