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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

How to build dynamic columns within a matrix in Desktop?

Dear All,

I am seeking for your support. I am using a matrix within Power BI Desktop, containing fields from a table and some measures (calculated values, e.g. price). I want to make the columns more dynamic, which means, to include a slicer to show or to hide columns. 

Below you will find an simplified example: two columns with a value per m2 (columns A and B); two columns with a price (columns C and D) and two columns with a  volume value (columns E and F) . I would like to create a slicer with three options: 'm2', ‘price’ and ‘volume value’. When you select the option 'm2', you only should see column A and B. Once you select the option 'total value' you only should see column C and D and once you select option ‘volume value’ you should only see columns E and F.

 

Beneath picture shows: complete matrix and how it should look like when I select one of the slicer variables.  Thanks in advance for any suggestion. Also another solution would be helpful, to achieve the same!

 

Thanks and regards,

PowerBIFellow_0-1617864329094.png

 

 

1 ACCEPTED SOLUTION

Hi, @Anonymous 

Thank you for your feedback.

Yes, you are right. The sort-order column has to be created, and you can use this to sort the measure name in the slicer, not by alphabetical order, but by sort-number-order.

 

Thank you.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


View solution in original post

16 REPLIES 16
AllisonKennedy
Super User
Super User

Do you already have the individual measures? If so, you can create a new unrelated table that has the values for: 

 

Select Measure to View:

Volume/Value

Price

m2

 

Then for each column create a measure:

ColumnA = 
SWITCH( SELECTEDVALUE(Slicer[Select Measure to View], "m2")

, "m2" , [m2A]

, "volume", [volumeA]

, "Volume/Value", [Volume/ValueA]

)

 

Then do the same for ColumnB using the B measures.

 

Note the second argument in the SELECTEDVALUE function is the default- in case they pick too many options or don't make a selection - what should they see?


Please @mention me in your reply if you want a response.

Copying DAX from this post? Click here for a hack to quickly replace it with your own table names

Has this post solved your problem? Please Accept as Solution so that others can find it quickly and to let the community know your problem has been solved.
If you found this post helpful, please give Kudos C

I work as a Microsoft trainer and consultant, specialising in Power BI and Power Query.
www.excelwithallison.com

massar2000
Frequent Visitor

Hi,

 

you can create two buttons. one to hide and the other to show columns. watch the below video 

 

https://www.youtube.com/watch?v=GnPuU3X74SY&list=LL&index=8

 

Regards,

Majed

Jihwan_Kim
Super User
Super User

Hi, @Anonymous 

Please correct me if I wrongly understood your question.

If "m2" /"price" / "volume value" are measures, then try to follow the below steps.

 

1. create a one-coloumn-table:   MeasureSlicerTable = {"m2", "price","volume value"}

2. create a measure:

Selected Measure =

Switch (True(),

selectedvalue ('MeasureSlicerTable'[Value]) = "m2", [m2],

selectedvalue ('MeasureSlicerTable'[Value]) = "price", [price],

selectedvalue ('MeasureSlicerTable'[Value]) = "volume value", [volume value] )

 

If it is OK with you, please share your sample pbix file's link here, then I can try to come up with more accurate measures.

 

Hi, My name is Jihwan Kim.

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Anonymous
Not applicable

Thanks for your reply. How can I share a sample pbix file? 

Hi, @Anonymous 

You can save your sample pbix file in Onedrive, Googledrive, or Dropbox, and you can share the link here.

 

Thank you.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Anonymous
Not applicable

Hi, @Anonymous 

Thank you for your feedback.

please check the link down below if it is OK.

 

https://www.dropbox.com/s/bqpan2i92jd3u2o/Test.pbix?dl=0 

 

 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Anonymous
Not applicable

Thanks! I will check later, since I first need to install a latest version of Power BI desktop, since I cannot open this file with my current version. 

Anonymous
Not applicable

Thanks! This seems to work perfectly! Really helpful!

 

I guess formatting of the different column values (decimals, etc ) I can manage within the measure 'Slicer Measure Select?

@Anonymous 

Yes, you can manage to change the format by selecting "Slicer Measure Select" measure.

Thank you.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Anonymous
Not applicable

Thanks Jihwan-Kim for this suggestion. 

 

However I am wondering since the 'Slicer Measure Select' contains different values, I could not manage one single format. I want to show values with zero, one and two decimals. I tried ROUND function, following number of decimals, but this failed. Curren;y it looks like this:

 

1 Slicer Measure Select =
2 SWITCH( SELECTEDVALUE(Tbl_SlicerMeasure[Measures]),
3 "Budget Volume / m2 (in kg / pieces)", [Budget Volume / m2 (in kg / pieces)], --> with zero decimal
4 "Budget - Volumes (in kg / pieces)", SUM(Qr_Creeer_Overview_Omzet_Raw_Data[Budget - Volumes (in kg / pieces)]), --> with zero decimals
5 "Budget Sales / m2 (in €)", [Budget omzet / m2 (in €)],  --> with two decimals
6 "Difference Sales per m2 (in %)", [Difference Sales per m2 (in %)], --> with one decimals
blank())

Hi, @Anonymous 

Thank you for your feedback.

One way to solve this is to write like below.

The below is just an example, and you can change and re-write the type of the format inside the measure.

 

Slicer Measure Select =
SWITCH( SELECTEDVALUE(SlicerMeasure[measures]),
"Actual sales per m2", FORMAT([Actual sales per m2],"€ #,##0.00"),
"Budget sales per m2", [Budget sales per m2],
"Actual volumes (in kg)", FORMAT( SUM(Tbl_Data_2[Actual volumes (in kg)]), " #,##0.00 KG"),
"Budget volumes (in kg)", SUM(Tbl_Data_2[Budget volumes (in kg)]),
"Actual sales (in €)", SUM(Tbl_Data_2[Actual sales (in €)]),
"Budget sales (in €)", SUM(Tbl_Data_2[Budget sales (in €)]),
"Actual price (in €)", FORMAT([Actual price (in €)],"€ #,##0.00"),
"Budget price (in €)", [Budget price (in €)],
blank())
 

Hi, My name is Jihwan Kim.

If this post helps, then please consider accept it as the solution to help other members find it faster, and give a big thumbs up.

Linkedin: https://www.linkedin.com/in/jihwankim1975/

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Anonymous
Not applicable

Thanks Jihwan Kim! This is what I need. I will play a bit with the format inside. really helpful.

 

Last question...;)  

 

How could I order the columns in the output (when I am using the measure)? I wrote a sequwence in the measure, but it seems it's sorted on alphabet. Should I better with numbering the columns in the measure, so to get it ordered in the way I want?

 

Thanks!

Hi, @Anonymous 

Thank you for your feedback.

Yes, you are right. The sort-order column has to be created, and you can use this to sort the measure name in the slicer, not by alphabetical order, but by sort-number-order.

 

Thank you.

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Anonymous
Not applicable

Thanks a lot Jihwan Kim. this was really helpful!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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