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
rs1249
Helper I
Helper I

How to collapse and expand columns in matrix

Hi Guys, 

I am creating a matrix so that value column A and value column B can be collapsed and expand to column C,

relationship between the columns is C = A + B

Matrix will be something like below:

    SUM C
IDNAMESUM DSUM ESUM ASUM B
Job1www123501112
Job2xxxx23341314
Job3zzzz23501516

 so column A & B can collapes into C and expand as well.

I tryied using hierachy, tried unpivote column A and B, it just doesn't work, when i try unpivote column A and B,

the table headers end up became like below: 

  SUM A SUM B 
IDNAMESUM DSUM ESUM DSUM E

if anyone can point me in the right direction or how me how to do this would be much appreciated.

 

Thanks in advance

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @rs1249 ,

 

This can be done following the steps below:

  • Unpivot all the columns you want to have the sum (not only A and B) this will give you a similar result as below:

 

ID Name Attribute Value
Job1 www D 123
Job1 www E 50
Job1 www A 11
Job1 www B 12
Job2 xxxx D 23
Job2 xxxx E 34
Job2 xxxx A 13
Job2 xxxx B 14
Job3 zzzz D 23
Job3 zzzz E 50
Job3 zzzz A 15
Job3 zzzz B 16

 

  • Create the following table:

 

CAT TOP CAT
A C
B C
E E
D D

 

  • MAke a relationship 1 -> Many linking CAT with Attribute
  • Setup your matrix in the following way:
    • Rows:
      • ID (Original table)
      • Name (Original Table)
    • Columns:
      • TOP CAT (New table created)
      • CAT (New table created)
    • Values:
      • Values (Original table)

Then expand on columns and rows the matrix to the last level, remove the subtotals and should give you the expected result.

 

Check PBIX file attach.

 

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

1 REPLY 1
MFelix
Super User
Super User

Hi @rs1249 ,

 

This can be done following the steps below:

  • Unpivot all the columns you want to have the sum (not only A and B) this will give you a similar result as below:

 

ID Name Attribute Value
Job1 www D 123
Job1 www E 50
Job1 www A 11
Job1 www B 12
Job2 xxxx D 23
Job2 xxxx E 34
Job2 xxxx A 13
Job2 xxxx B 14
Job3 zzzz D 23
Job3 zzzz E 50
Job3 zzzz A 15
Job3 zzzz B 16

 

  • Create the following table:

 

CAT TOP CAT
A C
B C
E E
D D

 

  • MAke a relationship 1 -> Many linking CAT with Attribute
  • Setup your matrix in the following way:
    • Rows:
      • ID (Original table)
      • Name (Original Table)
    • Columns:
      • TOP CAT (New table created)
      • CAT (New table created)
    • Values:
      • Values (Original table)

Then expand on columns and rows the matrix to the last level, remove the subtotals and should give you the expected result.

 

Check PBIX file attach.

 

Regards,

MFelix


Regards

Miguel Félix


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

Proud to be a Super User!

Check out my blog: Power BI em Português



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.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.