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
Sage477
New Member

Show correct SUM in subtotal / grandtotal rows in a Matrix

Hi, I am stuck with fixing the sub total for a matrix table I am using to create a report. The measure I created is using a switch function to check row category/level to provide specific calculation however I would like the sub total to sum all the values in each row in the table. 

CategoryMeasure
A5
B10
C20
total35

using the switch function If category is B then 2 * [value of A], if category is C, then its 4*[value of A] . The total should show the sum of the values in the table. 

1 ACCEPTED SOLUTION
v-zhangtin-msft
Community Support
Community Support

Hi, @Sage477 

 

You can try the following methods.

Measure 1 = 
VAR _SumA=CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),[Category]="A"))
RETURN
SWITCH(TRUE(),
SELECTEDVALUE('Table'[Category])="A",_SumA,
SELECTEDVALUE('Table'[Category])="B",2*_SumA,
SELECTEDVALUE('Table'[Category])="C",4*_SumA,BLANK())
Measure Result = 
Var _table=SUMMARIZE('Table','Table'[Category],"Sum",[Measure 1])
Var _Sumtotal=SUMX(_table,[Sum])
RETURN
IF(HASONEVALUE('Table'[Category]),[Measure 1],_Sumtotal)

vzhangtinmsft_0-1725332812735.png

Is this the result you expected?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-zhangtin-msft
Community Support
Community Support

Hi, @Sage477 

 

You can try the following methods.

Measure 1 = 
VAR _SumA=CALCULATE(SUM('Table'[Value]),FILTER(ALL('Table'),[Category]="A"))
RETURN
SWITCH(TRUE(),
SELECTEDVALUE('Table'[Category])="A",_SumA,
SELECTEDVALUE('Table'[Category])="B",2*_SumA,
SELECTEDVALUE('Table'[Category])="C",4*_SumA,BLANK())
Measure Result = 
Var _table=SUMMARIZE('Table','Table'[Category],"Sum",[Measure 1])
Var _Sumtotal=SUMX(_table,[Sum])
RETURN
IF(HASONEVALUE('Table'[Category]),[Measure 1],_Sumtotal)

vzhangtinmsft_0-1725332812735.png

Is this the result you expected?

 

Best Regards,

Community Support Team _Charlotte

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

ryan_mayu
Super User
Super User

@Sage477 

you can try this

Measure = SWITCH(SELECTEDVALUE('Table'[category]),"A",sum('Table'[value]),"B",CALCULATE(sum('Table'[value]),all('Table'[category]),'Table'[category]="A")*2,"C",CALCULATE(sum('Table'[value]),all('Table'[category]),'Table'[category]="A")*4,sum('Table'[value]))
 
11.PNG




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

Proud to be a Super User!




Hi thanks but the sub total is still showing incorrectly, it should add the values in the table. 

 

then you create another meausre

 

measure2=sumx(values('table'[catogry]),measure)





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

Proud to be a Super User!




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!

December 2024

A Year in Review - December 2024

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