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
elegant_cow
Regular Visitor

Row by Row calculation for a measure

Hi, 

I have a tables Load and Generation which are connected to table Timeseries through datetime. One datetime in Timeseries has multiple datetime in 'Load',which I filter by site. Similarly one datetime in timeseries has many datetimes in 'Generation'.

elegant_cow_0-1685516093364.png
I am trying to calculate the difference between Load[Load] and Generation[Generation] row by row before aggregating. 

My  first attempt is below and it works for the lowest drill down level but it aggregated and then subtracts. I need it to subtract and then aggregate.

Load_Generation_diff =
SUM ( Load[Load] ) - SUM ( Generation[Generation] )

Using the related function also doesn't work. likely due to the Many to one relationship

Load_Generation_diff =
SUMX ( 'Load', Load[Load] - RELATED ( Generation[Generation] ) )

 

5 REPLIES 5
DOLEARY85
Resident Rockstar
Resident Rockstar

Hi,

try wrapping the calculations in CALCULATE TO change the context to row calculation:

 

 

Load_Generation_diff =
CALCULATE(SUM ( Load[Load] )) - CALCULATE(SUM ( Generation[Generation] ))

 

then aggregate this after 

 

If I answered your question, please mark my post as solution, Appreciate your Kudos 👍

 

Unfortunately that doesn't solve the problem.

You should get an idividual calculation per row that you can then sum.

 

What's happening when you use it?

 

If I answered your question, please mark my post as solution, Appreciate your Kudos 👍

I am sorry, I think I misunderstood the real problem.

I can calulated the 'Load_Generation_diff' per row now (as per your forumla) and I am trying to calculate another measure from it. This measure is called 'Generation Sold'

Generation Sold = IF( [Load_Gen_diff] < 0ABS([Load_Gen_diff]) ,0)

My data is hourly so at the hourly level it all works (and it worked before as well)
elegant_cow_0-1685536887751.png

but as soon as I aggregate up (from hourly to daily), the 'Generation sold' doesnt show anything. I thought this was being 'Load_Generation_diff was no longer calculating per row (even with the new formula).

elegant_cow_1-1685537043854.png

Sorry for not explaining the problem properly

Ah okay, i'm not sure without knowing the data model and fields - Are you able to share the PBIX file? or some sample data?

 

If I answered your question, please mark my post as solution, Appreciate your Kudos 👍

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.