Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Good morning,
I am working on such calculations:
I have a column with Hours and Hours Used. For Hours used I need to calculate Running Total, what I have a DAX for it no problem.
My problem starts with calculating a Balance.
I need to subtract Hours Used Running Total always from the first available date for Hours (01/01/2025 – 100 in my example table)
In Excel it would be like Balance = $B$3 – E3, next row $B$3 – E4 etc., but I cannot find a solution how to do this in DAX.
Would appreciate help with this.
Kind regards,
Agata
Date | Hours | Hours used | Hours Used Running Total | Balance |
01/01/2025 | 100 | 10 | 10 | 10 |
02/01/2025 | 200 | 60 | 70 | 30 |
03/01/2025 | 300 | 10 | 80 | 20 |
04/01/2025 | 100 | 20 | 100 | 0 |
05/01/2025 | 500 | 20 | 120 | -20 |
06/01/2025 | 300 | 30 | 150 | -50 |
07/01/2025 | 400 | 40 | 190 | -90 |
08/01/2025 | 400 | 30 | 210 | -110 |
09/01/2025 | 200 | 50 | 260 | -160 |
10/01/2025 | 100 | 10 | 270 | -170 |
Solved! Go to Solution.
Try this
Answer =
// get first date
var myfirstdate =
CALCULATE(
MIN(yourdata[Date]),
ALl(yourdata)
)
// get hours for first date
var myfirstvalue =
CALCULATE(
SUM(yourdata[Hours]),
ALL(yourdata),
yourdata[Date] <= myfirstdate)
// get date for current row in visual
var mydate = SELECTEDVALUE(yourdata[Date])
// get running total for row
var runningtotal =
CALCULATE(
SUM(yourdata[Hours used]),
ALL(yourdata),
yourdata[Date] <= mydate)
RETURN
// deduct running toral from first value
myfirstvalue - runningtotal
Please click the [accept solution] and thumbs up buttons. Thank you
Thanks @AgataJ
Your new issue is a bit vague and a new problem that will require a new solution.
Please raise a new ticket rather than append to this one, otherwise uit gets confussing which is which.
If you quote @speedramops then I wil receive an automatic notification.
In you new ticket please provide:-
Take care to use the same column names in the input, output and description.
Use Power Bi terminnology. If you mean Slicer then say slicer and not Filter.
You will get quicker and better replies if you take the time and effort to ask clear and comprehensive questions with example data.
Thank you
@AgataJ please review my solution and either click [accept solution] and the thumbs up button or provide more details, thank you 😀
Hi,speedramps ,thanks for your concern about this issue.
Your answer is excellent!
And I would like to share some additional solutions below.
Hello,@AgataJ .I am glad to help you.
After my test, the test data provided by speedramps is correct. In addition, I noticed that there is an error in the test data provided by you, which may cause misunderstanding
I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian
Try this
Answer =
// get first date
var myfirstdate =
CALCULATE(
MIN(yourdata[Date]),
ALl(yourdata)
)
// get hours for first date
var myfirstvalue =
CALCULATE(
SUM(yourdata[Hours]),
ALL(yourdata),
yourdata[Date] <= myfirstdate)
// get date for current row in visual
var mydate = SELECTEDVALUE(yourdata[Date])
// get running total for row
var runningtotal =
CALCULATE(
SUM(yourdata[Hours used]),
ALL(yourdata),
yourdata[Date] <= mydate)
RETURN
// deduct running toral from first value
myfirstvalue - runningtotal
Please click the [accept solution] and thumbs up buttons. Thank you
Hi @speedramps ,
My bad, I focused on the project and forgot to asnwer. Your code works well, thanks a million!
I had to filter it to start the calculation from the first date when Cum_Complete is not blank. I did it using this code:
Thanks in advance,
Agata
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
81 | |
75 | |
60 | |
37 | |
33 |
User | Count |
---|---|
102 | |
56 | |
52 | |
46 | |
40 |