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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

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
Anonymous
Not applicable

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
Anonymous
Not applicable

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 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.