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

Running balance (difference) by groups

I'm trying to calculate running balance for quantity on hand after usage.

My sample table looks like this. Any idea on what I need to do to get the expected value?

Index 1Index 2ComponentStart DateOn handQty requiredRunning Balance (expected value)
11A1/1/20241028
22A1/2/20241026
31B1/1/2024514
42B1/2/2024513
51C1/1/202415114
62C1/2/202415113
71D1/1/20241028
81E1/1/2024514
92E1/2/2024513
103E1/3/2024512
1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Why is On hand repeated?  Shouldn't that be only listed for the first date?

 

lbendlin_0-1729632233827.png

 

Measure:

Running Balance = 
var c = SELECTEDVALUE('Table'[Component])
var i = SELECTEDVALUE('Table'[Index 2])
var b = filter(ALLSELECTED('Table'),[Component]=c && [Index 2]<=i)
return maxx(b,[On hand])-sumx(b,[Qty required])

View solution in original post

2 REPLIES 2
Kedar_Pande
Super User
Super User

Running Balance =
CALCULATE(
MAX(SampleTable[On hand]) - SUMX(
FILTER(
SampleTable,
SampleTable[Component] = EARLIER(SampleTable[Component]) &&
SampleTable[Start Date] <= EARLIER(SampleTable[Start Date])
),
SampleTable[Qty required]
)
)

lbendlin
Super User
Super User

Why is On hand repeated?  Shouldn't that be only listed for the first date?

 

lbendlin_0-1729632233827.png

 

Measure:

Running Balance = 
var c = SELECTEDVALUE('Table'[Component])
var i = SELECTEDVALUE('Table'[Index 2])
var b = filter(ALLSELECTED('Table'),[Component]=c && [Index 2]<=i)
return maxx(b,[On hand])-sumx(b,[Qty required])

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.