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

How to put calculated columns in the rows of a matrix

I’m having trouble to create a matrix table that contains columns calculated.

 

SoufTC_0-1655476193230.png

 

I have a data which appears as following :

|   User |  Col 1  |     Col2    |    Col3

---------------------------------------

|   1      |     20   |        5       |      10

|   2      |     4     |       50      |       44

|   3      |     4     |       4        |       49

 

Col1, Col2 and Col3 are calculated columns

 

Desired matrix is the following:  

 

nameTotal

Col1

28
Col259
Col3103

 

Please, any help?

Thank's in advance

1 ACCEPTED SOLUTION

Hi @SoufTC , I think I understand what you are going for! 

 

In order to get the desired result , we would have to somehow unpivot the data table such that the columns become rows. Since you mentioned the columns are calculated columns, we would have to resort to DAX to implement that.

 

One idea is to create a new table from the original table such that the columns become row values (unpivoting) using DAX like so:

 

 

Data_Unpivoted = 
UNION(
SELECTCOLUMNS(Data, "Name","Col1", "Total", Data[Col1]),
SELECTCOLUMNS(Data, "Name","Col2", "Total", Data[Col2]),
SELECTCOLUMNS(Data, "Name","Col3", "Total", Data[Col3])
)

 

 

Resulting table Data_Unpivoted looks like this:

sathya_s_0-1655744911096.png

Now, in the Matrix visual, we are able to drop the Data_Unpivoted[Name] column in the Row field and Data_Unpivoted[Total] column in the Value field. Thus getting this visual:

sathya_s_1-1655745120513.png

The DAX code we have above basically does 2 things:

1. Selects the specified column and lists out the values under it and tags the the column name under Name column of new table.

2. When we have listed all columns like this, we use UNION() to combine them together into a single table.

 

Hope this is meets your requirements. 😀

View solution in original post

4 REPLIES 4
v-yalanwu-msft
Community Support
Community Support

Hi, @SoufTC ;

You could add another table,the create a measure.

1.create a new table.

Table 2 = {"Column1","Column2","Column3"}

2.create a measure.

value = SWITCH(MAX('Table 2'[column]),"Column1",SUM('Table'[Column1]),"Column2",SUM('Table'[Column2]),"Column3",SUM('Table'[Column3]))

The final show:

vyalanwumsft_0-1655788551641.png


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

sathya_s
Frequent Visitor

Hi SoufTC,

 

One of the simplest ways to do this would be to - toggle the "switch values to rows" option on.

Let me explain:

Step1: Add the columns to the values field 

sathya_s_0-1655486882860.png

 

Step2: In the "Format Your Visual" tab, under "Values", under "Options", toggle the "Switch values to rows" option on.

sathya_s_2-1655487095280.png

 

 

This should give the result like below:

sathya_s_1-1655487074464.png

 

Hope this is what you were looking for.

@sathya_s  thank you for your answer but it is not this technique that I wish to use because I would have to add other values in the matrix ! Also I would like to have the possibility to name the column

Hi @SoufTC , I think I understand what you are going for! 

 

In order to get the desired result , we would have to somehow unpivot the data table such that the columns become rows. Since you mentioned the columns are calculated columns, we would have to resort to DAX to implement that.

 

One idea is to create a new table from the original table such that the columns become row values (unpivoting) using DAX like so:

 

 

Data_Unpivoted = 
UNION(
SELECTCOLUMNS(Data, "Name","Col1", "Total", Data[Col1]),
SELECTCOLUMNS(Data, "Name","Col2", "Total", Data[Col2]),
SELECTCOLUMNS(Data, "Name","Col3", "Total", Data[Col3])
)

 

 

Resulting table Data_Unpivoted looks like this:

sathya_s_0-1655744911096.png

Now, in the Matrix visual, we are able to drop the Data_Unpivoted[Name] column in the Row field and Data_Unpivoted[Total] column in the Value field. Thus getting this visual:

sathya_s_1-1655745120513.png

The DAX code we have above basically does 2 things:

1. Selects the specified column and lists out the values under it and tags the the column name under Name column of new table.

2. When we have listed all columns like this, we use UNION() to combine them together into a single table.

 

Hope this is meets your requirements. 😀

Helpful resources

Announcements
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.

June 2025 community update carousel

Fabric Community Update - June 2025

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