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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
wulawula
Frequent Visitor

How to get total number in power bi matrix rows

Here's a sample of raw data in the Power BI table. 

 

Col ACol BCol CCol DCol E
AABCD2019-Q31291%
AABCD2019-Q43791%
AABCD2020-Q14686%
AABCD2020-Q26076%
AAEF2019-Q31287%
AAEF2019-Q43987%
AAEF2020-Q14899%
AAEF2020-Q24997%
AAGH2019-Q31296%
AAGH2019-Q43997%
AAGH2020-Q148100%
AAGH2020-Q249100%

 

I want to sum the numbers of Col D group by Col B and Col C and list them as an aggregate number in matrix rows. How can I get the desire layout like this? It seems easy but couldn't figure it out. Thank you in advance!

 

Col ACol BCol D2019-Q32019-Q42020-Q12020-Q2
AABCD15591%91%86%76%
 EF14887%87%99%97%
 GH14896%97%100%100%

 

Sorry I forgot to mention Col C is a growing list, like it will show 2020-Q3, 2020-Q4... and also will show previous quarters like 2019-Q2. The Col D sum numbers is the result filtered from the slicer outside the matrix.

1 ACCEPTED SOLUTION
PaulDBrown
Community Champion
Community Champion

@wulawula 

 

Alternatively, if you want the DIM period table to also filter the columns on the converted matrix, you can try the following measure to use in the filter panel for the Matrix:

 

FILTER Matrix columns = 
VAR dim = VALUES('Dim Period'[AppCol])
VAR clod = CALCULATETABLE(VALUES('Matrix Columns'[MtrxCol]), 'Matrix Columns'[MtrxCol] IN {"ColD"})
VAR REF = UNION(dim,clod)
VAR matrix = VALUES('Matrix Columns'[MtrxCol])
RETURN
COUNTROWS(INTERSECT(REF,matrix))

 

 

And you get this (I've also altered the "ColD" measures to give you the total for the column in the matrix):
No filters for period

not filterd columns.JPG

 

Filters applied to DIM period:

filtered columns.JPG

 

New PBIX file attached





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






View solution in original post

6 REPLIES 6
PaulDBrown
Community Champion
Community Champion

@wulawula 

 

Alternatively, if you want the DIM period table to also filter the columns on the converted matrix, you can try the following measure to use in the filter panel for the Matrix:

 

FILTER Matrix columns = 
VAR dim = VALUES('Dim Period'[AppCol])
VAR clod = CALCULATETABLE(VALUES('Matrix Columns'[MtrxCol]), 'Matrix Columns'[MtrxCol] IN {"ColD"})
VAR REF = UNION(dim,clod)
VAR matrix = VALUES('Matrix Columns'[MtrxCol])
RETURN
COUNTROWS(INTERSECT(REF,matrix))

 

 

And you get this (I've also altered the "ColD" measures to give you the total for the column in the matrix):
No filters for period

not filterd columns.JPG

 

Filters applied to DIM period:

filtered columns.JPG

 

New PBIX file attached





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






PaulDBrown
Community Champion
Community Champion

@wulawula 

 

You can achieve this by using a disconnected "Matrix Columns" table, which basically includes the column header "ColD" & the values for the periods (created in Power Query by isolating column header "ColD", creating a DIM table for the periods and appending both - index added for sorting purposes). Since the table is created by appending values from the dataset, it will grow accordingly:

 

Matrix col table.JPG

The model looks like this:
Model.JPG

 

Create standard measures (SUM) for values for ColD and ColE form the original fact table.

 

Sum of Values ColD = SUM('Orig Fact'[Col D])

Sum of Period Values = SUM('Orig Fact'[Col E])

 

Next create  measures to identify which of the above to use in the filter context of the columns in the matrix:

 

Sel Period Values = CALCULATE([Sum of Period Values], TREATAS(VALUES('Matrix Columns'[AppCol]), 'Orig Fact'[Col C]))

 

 

Sel Value ColD = CALCULATE([Sum of Values ColD], ALLSELECTED('Dim Period'[AppCol]))

 

and 

 

Selected Value = IF(
SELECTEDVALUE('Matrix Columns'[AppCol]) = "ColD", FORMAT([Sel Value ColD], "###"), 
FORMAT([Sel Period Values], "##%"))

 


 Add the ColA and ColB to a matrix as rows; add the "Matrix columns" as Columns and [Selected Value] as values and you get this:
result.JPG

 

Filtered.JPG

 

 

I've included the PBIX file for your reference





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






Thank you so much for the help! It seems a good solution for the case. I'll try this out!

Greg_Deckler
Community Champion
Community Champion

@wulawula Yeah, so you are looking to add an "extra" total column to your matrix. Turns out that is not actually so easy, but there is a way to do it.

https://community.powerbi.com/t5/Quick-Measures-Gallery/The-New-Hotness-Custom-Matrix-Hierarchy/m-p/...



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thank you Greg! I'm sorry forgot mention the quarters are based on the filtered result from the outside slicers.

 

Yes, it's not easy as I thought. I thought it could be resolved by a calculated column like NewColumn = CALCULATE( SUM('Table'[COL D]) , ALLEXCEPT('Table', 'Table'[COL A],'Table'[COL B],'Table'[COL C] )) to solve the problem. But it doesn't work. Col A will be thousands of names there. So it would be a long list according to your suggestion and has to be a dynamic one. Not sure if that would apply to my case. Still thinking if there's a better way to resolve this. Thank you so much!

@wulawula 

 

I am not sure if you have considered this:

 

One alternative is to pivot the Col C with values from Col E

vivran22_0-1598757501435.png

 

 

The trade-off would be that we need to manually add the newly included quarter in the matrix:

 

vivran22_1-1598757676981.png

 

 

 

Cheers!
Vivek

Blog: vivran.in/my-blog
Connect on LinkedIn
Follow on Twitter

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.