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 total by group and by date

Hello,

I have the following table and i am trying to create a running total column for the Invoice column for each Document ID by Received date. The date format is: dd/mm/yy

From my understanding, the first step would be to sort the Document ID column and then the Received date column should be sorted in order starting from oldest date but it should keep the Invoice amount according to the date on the same row. Then, the running total should be calculated separately for each Document ID. I'm not sure if it's better to do this in Power Query or DAX but any help is much appreciated!

 

Document IDReceivedInvoice
399801/07/2022398
399807/04/2022178
399806/02/2022451
406005/01/2022646
413905/05/2022657
414506/07/2022443
414905/06/2022155
415005/08/2022408
415010/07/2022704
415105/09/2022411
415205/10/2022403
416615/07/2022472
416825/07/2022729
416905/08/2022670
416902/01/2022548
418709/04/2022414
424822/02/2022185
424805/03/2022110
424806/03/202288
424815/04/2022250
424921/01/2022644
425011/03/20221546
448125/02/2022583
448715/01/2022661
449507/07/20221419
468526/02/20225446
468617/03/2022545
468725/06/2022654
468801/02/20221398
468802/03/20222574
468817/05/20223384
493109/05/2022658
499718/08/2022713
499719/06/2022421
513905/05/20227487
523216/04/2022646
532522/04/2022451
541829/05/2022613
551229/07/2022751
560528/08/2022184

 

Expected results (partial):

Document IDReceivedInvoiceRunning Total
399806/02/2022451451
399807/04/2022178629
399801/07/20223981027
406005/01/2022646646
413905/05/2022657657
414506/07/2022443443
414905/06/2022155155
415010/07/2022704704
415005/08/20224081112
415105/09/2022411819
1 ACCEPTED SOLUTION
Anonymous
Not applicable

@HotChilli I have created the following quick measure:

MakeItReal_0-1659033737931.png

 

The corresponding auto-generated DAX code:

Invoice running total in Received = 
CALCULATE(
	SUM('Invoice Table'[Invoice]),
	FILTER(
		ALLSELECTED('Invoice Table'[Received]),
		ISONORAFTER('Invoice Table'[Received], MAX('Invoice Table'[Received]), DESC)
	)
)

 

The results in a table is correct:

MakeItReal_3-1659035736747.png

 

View solution in original post

5 REPLIES 5
HotChilli
Super User
Super User

Good stuff.  I pointed you in the right direction and you got it done.

HotChilli
Super User
Super User

There is a Running Total Quick Measure for this.  Also the Expected result for Invoice 4150 doesn't look right

Anonymous
Not applicable

@HotChilli Thanks for your reply! I will investigate the Running Total Quick Measure but it should be limited per Document ID. I have fixed the expected results.

Anonymous
Not applicable

@HotChilli I have created the following quick measure:

MakeItReal_0-1659033737931.png

 

The corresponding auto-generated DAX code:

Invoice running total in Received = 
CALCULATE(
	SUM('Invoice Table'[Invoice]),
	FILTER(
		ALLSELECTED('Invoice Table'[Received]),
		ISONORAFTER('Invoice Table'[Received], MAX('Invoice Table'[Received]), DESC)
	)
)

 

The results in a table is correct:

MakeItReal_3-1659035736747.png

 

Hi I used this fine on just dates, but as soon as I put the year into a pivot table the calculation begins from fresh each year in the rolling count of the buy quantity. Any ideas how to alter the formula to correct?

 

ie 27/01/2021 should be 29, 13 from 1st year and 16 from the transaction on the 17/01/2021

rends_04_0-1710848585437.png

 

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.