Forum Discussion

gvlado's avatar
gvlado
Icon for Advocate III rankAdvocate III
2 years ago
Solved

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 !?

 

        
 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.

  • Anonymous's avatar
    Anonymous
    2 years ago

    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.

    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

     

     

     

    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.

  • gvlado's avatar
    gvlado
    2 years ago
    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---

9 Replies

  • Nithinr's avatar
    Nithinr
    Icon for Resolver III rankResolver III

    Is this the one you are looking for

    Reverse Cumulative Total = 
    CALCULATE(
        SUM('Table'[Inventory]),
        FILTER(
            ALL('Table'),
            'Table'[Date] >= MIN('Table'[Date])
        )
    )
  • Anonymous's avatar
    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.

    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

     

     

     

    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.

    • gvlado's avatar
      gvlado
      Icon for Advocate III rankAdvocate III
      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---
    • gvlado's avatar
      gvlado
      Icon for Advocate III rankAdvocate III

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

       

  • dvraan's avatar
    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])
  • 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?

  • gvlado's avatar
    gvlado
    Icon for Advocate III rankAdvocate 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.