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
gvlado
Advocate III
Advocate III

Running totals backwards

Dear community friends 
I am curious about how to make measure for running totals backwards - from today back into the past.
I have Today inventory, at the end of the day (900),
Also have income end outcome of the inventory for each day (also for this last day - Today)
Question is how to make measure that will calculate inventory for each day backwards !?

gvlado_0-1709041021247.png

 

        
 Inventory at the begining of Today 01.03.2024 was =1000  
        
#DateINOUTIN-OUTInventory  
101.03.2024100200-100900 at the end of the day (Today)
229.02.20241020-10890  
328.02.20243001002001090  
427.02.202420020001090  
526.02.202410050501140  
625.02.202410200-190950  
724.02.20245060-10940  
923.02.20241005050990  
1022.02.202410040601050  
1121.02.2024300301080  
1220.02.2024050-501030  
1319.02.20242010101040  
..................  

Ice cream is free by me. 
Thanks a lot for your effort.

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @gvlado ,

As Nithinr said, it is possible to do what you need to do based on this DAX code, here are my thoughts and additions.

First create a table.

vyilongmsft_0-1709175010799.png

A slight change to Nithinr's DAX code will give you the results you need.

MEASURE =
VAR _A =
    CALCULATE (
        SUM ( 'Table'[IN-OUT] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Date] >= MIN ( 'Table'[Date] ) )
    )
VAR _AA = _A + 900
RETURN
    _AA

vyilongmsft_1-1709175104722.png

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Small correction 900 -> 1000
And types of columns must be defined
---- BOMeasure----------
Measure
=
VAR _A = CALCULATE(
    SUM('Table'[IN-OUT]),
    FILTER(
        ALL('Table'),
        'Table'[Date] >= MIN('Table'[Date])
    )
)
VAR _AA = _A + 1000
RETURN
_AA
--- EOMEasure---

View solution in original post

9 REPLIES 9
dvraan
Frequent Visitor

Inventory = 
VAR PreviousRowValue = 
    CALCULATE(
        SUM('Table'[IN-OUT]) + 1000,
        FILTER(
            'Table',
            'Table'[Date] > EARLIER('Table'[Date])
        )
    )
RETURN
    IF(ISBLANK(PreviousRowValue), 'Table'[IN-OUT], PreviousRowValue + 'Table'[IN-OUT])
gvlado
Advocate III
Advocate III

It should go like ilustration on the excell
Starting inventory for beginning of the day is separated table. IN-OUT is change for each day (it is 2nd table)
After loading both table I have Inventory and Change of inventory by day backwards (1000 - 100=900, then 900 - 10=890,  then 890+200=1090, ....etc). The question is how measure for Inventory at the end of the day should look like.

gvlado_2-1709197093815.png

 

Ashish_Mathur
Super User
Super User

Hi,

For closing inventory on 1/3/2024 to be 900, the closing inventory on 29/2/2024 should be 1000.  Why is it 890?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

It is because receiving (IN=10) and deliveiring (OUT=20) -> means that this day was inventory smaller for 10 (-10). So, I have in and out for every day. Only for last day (1/3/2024) there is data fon inventory at the end of the day. It means calculation of inventory starts from 1000.

Hi,

I have solved a similar problem in the attached PBI files.  Please review them and adapt them to your setup.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hi @gvlado ,

As Nithinr said, it is possible to do what you need to do based on this DAX code, here are my thoughts and additions.

First create a table.

vyilongmsft_0-1709175010799.png

A slight change to Nithinr's DAX code will give you the results you need.

MEASURE =
VAR _A =
    CALCULATE (
        SUM ( 'Table'[IN-OUT] ),
        FILTER ( ALL ( 'Table' ), 'Table'[Date] >= MIN ( 'Table'[Date] ) )
    )
VAR _AA = _A + 900
RETURN
    _AA

vyilongmsft_1-1709175104722.png

 

 

 

Best Regards

Yilong Zhou

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Small correction 900 -> 1000
And types of columns must be defined
---- BOMeasure----------
Measure
=
VAR _A = CALCULATE(
    SUM('Table'[IN-OUT]),
    FILTER(
        ALL('Table'),
        'Table'[Date] >= MIN('Table'[Date])
    )
)
VAR _AA = _A + 1000
RETURN
_AA
--- EOMEasure---

how did you get 940?
Should go like it is on ilustration

gvlado_0-1709196895700.png

 

Nithinr
Resolver III
Resolver III

Is this the one you are looking for

Reverse Cumulative Total = 
CALCULATE(
    SUM('Table'[Inventory]),
    FILTER(
        ALL('Table'),
        'Table'[Date] >= MIN('Table'[Date])
    )
)

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.