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

Level up your Power BI skills this month - build one visual each week and tell better stories with data! Get started

Reply
ikibirev
Frequent Visitor

How to calculate totals by rows?

It would seem a simple question, but I can’t solve it in Power BI...

You can get pbix exampe via this link (unfortunately direct loading is not available for me in this forum):

https://www.dropbox.com/s/vmt0z7n8ai3phgq/DAX%20Issue%20Example%202.pbix?dl=0 

 

In this example I'm getting zero values for the totals of columns Effect and MixEffect:

 

ikibirev_0-1642069167448.png

But I need get 130 (35 + 50 + 45) and 830 (140 + 150 + 540).

 

This example is based on the following simple data:

ikibirev_1-1642069504722.png

 
The following measures are used:
Val1Totals = calculate(sum('TestTable'[Val1]), ALLSELECTED('TestTable'))
Effect = 'TestTable'[Val1Totals] - sum('TestTable'[Val1])
MixEffect = sum('TestTable'[Val2]) * 'TestTable'[Effect]
 
Or the same result in one formula:
MixEffect2 = (calculate(sum('TestTable'[Val1]), ALLSELECTED('TestTable')) - sum('TestTable'[Val1])) * sum('TestTable'[Val2])
 
How can I get 830 for MixEffect? May be as another measure... Or an intermediate table...
 
I would be grateful for any advice. This is not a fictional example, there is a real need to calculate the COGS effect.
 
Thank you!
 
1 ACCEPTED SOLUTION
smpa01
Community Champion
Community Champion

@ikibirev  you can write these two measures

_effect = SUMX(VALUES(TestTable[Category]),[Effect])

_effect = SUMX(VALUES(TestTable[Category]),[Effect])

 

 

 

smpa01_0-1642084213224.png

 


========================
Did I answer your question? Mark my post as a solution!
Proud to be a Super User
My Custom Visualization Projects
• Plotting Live Sound: Live Sound
• Beautiful News: Women in Parliament, Energy Mix, Shrinking Armies
• Visual Capitalist: Working Hrs
• Others: Easing Graph, Animated Calendar
MayViz Submissions
• Week 1: View
• Week 2: View
========================

View solution in original post

6 REPLIES 6
smpa01
Community Champion
Community Champion

@ikibirev  you can write these two measures

_effect = SUMX(VALUES(TestTable[Category]),[Effect])

_effect = SUMX(VALUES(TestTable[Category]),[Effect])

 

 

 

smpa01_0-1642084213224.png

 


========================
Did I answer your question? Mark my post as a solution!
Proud to be a Super User
My Custom Visualization Projects
• Plotting Live Sound: Live Sound
• Beautiful News: Women in Parliament, Energy Mix, Shrinking Armies
• Visual Capitalist: Working Hrs
• Others: Easing Graph, Animated Calendar
MayViz Submissions
• Week 1: View
• Week 2: View
========================

smpa01

Greate! You are Superb!

The formula in your answer was slightly not exactly copy-pated, but I got the idea. Merged this answer with ValtteriN answer.

So the result formulas are:

_mixEffectTotal =
if(selectedvalue('TestTable'[Category]) <> blank(),
[MixEffect],
sumx(values(TestTable[Category]),[MixEffect]))

 

ikibirev_0-1642085090011.png

Thank you very much!

ValtteriN
Community Champion
Community Champion

Hi,

The total of a matrix uses the same logic as with the measure in the column. To create a custom total which calculates all of the values you can use SUMX and IF.

Here is a very similar solution to your case: 
https://community.powerbi.com/t5/DAX-Commands-and-Tips/Total-wrong/m-p/2268244#M55107


The basic dax is as follows:

Custom total  =
if(SELECTEDVALUE(table[column])<>BLANK(),[your measure],CALCULATE(SUMX(ALL(table),[your measure])))


I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!






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

Proud to be a Super User!




ValtteriN,

 

A very interesting idea! But unfortunately the result is different from zero, but has the wrong value (1450 instead 830):

 

ikibirev_0-1642071879884.png

 

amitchandak
Super User
Super User

@ikibirev , Try like

MixEffect = sumX('TestTable', 'TestTable'[Val2] * ([Val1Totals] - 'TestTable'[Val1]) )

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

amitchandak,

Unfortunately, the proposed formula gives a different result (1050 instead 830):

 

ikibirev_0-1642070792070.png

 

Helpful resources

Announcements
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.