Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago

Cumulative Column But only adding if previous row was negative

Hi All,

 

I'm trying to create a calc column that is cummulative but only with negative values. Ive tried a bunch of solutions but havent had much luck so any help is appreciated!

 

This is my code(Note: It does just a regular cummulative atm):

 

 

 

VAR Expiry = CALCULATE(SUM('Table'[Qty]), FILTER('Table', EARLIER('Table)'[Date])>='Table'[Date]))

 

 

Example Table:

DateQtyExpired
1/1/20233030
1/4/20232020
1/5/2023-10-10
1/10/2023-60-70
1/11/202310030

5 Replies

  • Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    This is pretty close, the issue is that the negative values should decrease(if postitive) or increase(if negative) depending on the Qty and not just be a sum of all negative vaules.  I've include a example that showcases that a bit better. This ones got me stumped. Thank you for you time!

    DateQtyExpired
    1/1/20233030
    1/4/2023-20-20
    1/5/202310-10
    1/10/20234030
    1/11/2023-50-50
    1/12/202310-40
    1/1/2024-5-45
    1/2/202430-15
    1/3/2024205
      • Anonymous's avatar
        Anonymous
        Not applicable

        Effectivly what I showed in the table, im creating this to find expected expiry stock. so for each date period any positive values(expired stock) would not be added to the next date but any negative values(remaining consumption) would be added to the calculation of next dates expired stock. The issue is it should really only be factoring whatever the previous date expired stock would be in calculating the current dates expired stock.