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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
janani80
Frequent Visitor

Matrix Report- Dynamic column headers

I am pretty new to powerbi and I am required to create a matrix visual based on the table below. Based on slicer selection the header should dynamically change. 

 

YearProductNo of Units manufacturedDefective PiecesTotal SalesOutstanding OutputDiscounted items
2022Handbag50001004000800100
2022Purse3000020252304500250
2022Briefcase250030235010020
2022Suitcase6500455955400100
2022Wallet4310100396020050
2023Handbag40002325801000397
2023Purse20000120150004000880
2023Briefcase2100211700100279
2023Suitcase6300605700400140
2023Wallet4100223000100078
2024Handbag3400022532635900240
2024Purse34000200325901000210
2024Briefcase25000105230001345550
2024Suitcase1250020599702200125
2024Wallet4500065043000800550

 

If I select a 2023 as the year the data should reflect as below. If I select the year as 2022 the 1st 2 columns should display data for 2021 and the next 3 columns for 2022 and so on. The Year should dynamically change.

 

 20222023
ProductSalesOutstanding OutputNo of Units manufacturedDefective PiecesDiscounted items
Handbag4000800400023397
Purse25230450020000120880
Briefcase2350100210021279
Suitcase5955400630060140
Wallet396020041002278

 

Thanks in advance

1 ACCEPTED SOLUTION

Thanks hnguy71.. It worked now.. And sorry to disturb you on a weekend.

View solution in original post

6 REPLIES 6
v-xinc-msft
Community Support
Community Support

Thank you for the reply from hnguy71  and lbendlin!

Hi @janani80 ,

Did the reply hnguy71 offered help you solve the problem, if it helps, you can consider to accept it as a solution so that more user can refer to, or if you have other problems, you can offer some information so that can provide more suggestion for you.

If the above ones still not help you get the expected result, could you please provide example data or sample files here if you have any confused? We could offer you more help if we have information in detail. And what you expect the output to be. There is sensitive data that can be removed in advance. How to provide sample data in the Power BI Forum - Microsoft Fabric Community

Thanks for your understanding. Your time and cooperation are much valued by us. We are looking forward to hearing from you to assist further.

Best regards,

Lucy Chen

hnguy71
Super User
Super User

Hi @janani80 

While there isn't a straightforward method for it, with a bit of creativity, it's possible.

 

You'll need at least two disconnected tables similar to this:

hnguy71_0-1735870862732.png


The "Disconnected_Yrs" table is just the unique values of your years in your dataset. For simplicity sake, I built it in DAX with the following expression:

Disconnected_Yrs = DISTINCT('FACT'[Year])

 

The "Metric" table is a table built using the "Enter Data" functionality with the metrics you want to evaluate:

hnguy71_1-1735870981389.png

 

Next, you'll have to create your metric calculation:

Metric_Analysis = 
// What's the current year being evaluated on the matrix visual
VAR _CurrYear = MAX('FACT'[Year])

// What is the selected year by the user?
VAR _SelectedYr = SELECTEDVALUE(Disconnected_Yrs[Year], MAX(Disconnected_Yrs[Year]))

// What is the current metric being evaluated on the matrix visual?
VAR _Metric = SELECTEDVALUE(Metric[Metric])

RETURN

// Determines which year to show which metric.
SWITCH( TRUE(),
    _Metric = "Total Sales" && _CurrYear = _SelectedYr - 1,  CALCULATE(SUM('FACT'[Total Sales]), 'FACT'[Year] = _SelectedYr - 1) ,  
    _Metric = "Outstanding Output" && _CurrYear = _SelectedYr, CALCULATE(SUM('FACT'[Outstanding Output]), 'FACT'[Year] =_SelectedYr),
    _Metric = "Units Manufactured" && _CurrYear = _SelectedYr, CALCULATE(SUM('FACT'[No of Units manufactured]), 'FACT'[Year] = _SelectedYr),
    _Metric = "Defective Pieces" && _CurrYear = _SelectedYr, CALCULATE(SUM('FACT'[Defective Pieces]), 'FACT'[Year] = _SelectedYr),
    _Metric = "Discounted Items" && _CurrYear = _SelectedYr, CALCULATE(SUM('FACT'[Discounted items]), 'FACT'[Year] = _SelectedYr)
)

 

All that's left is to build a matrix visual. For the simplicity of this excercise, Product and Year are from the same table. Metric is from the disconnected table and the Year slicer is also from the disconnected table. And here's the results:

hnguy71_2-1735871313249.gif

 



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

Hi hnguy71

Thanks for the calculations, however when I tried the same measure for my report(the data is different) I did not get the desired output. Hence I used the same data which I shared with you and the same steps but still I did not get the desired output. I had added the product in the rows, Year in column and the Measure(Metric_Analysis) in the value section. Below is the printscreen for your reference. Am I doing some step wrong?

janani80_0-1735994988204.png

 

Thanks

Janani80

Hi @janani80 ,
Seems you're also missing the Metric field on the Columns well.

 

Here's a sample pbix for you to play around: janani80_disconnected_matrix.pbix



Did I answer your question?
Please help by clicking the thumbs up button and mark my post as a solution!

Thanks hnguy71.. It worked now.. And sorry to disturb you on a weekend.

lbendlin
Super User
Super User

Tell the requestor that is not something you do in Power BI.  Better stay in Excel.

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!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

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