Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Use previous rows for calculation

dear all,

 

I'm in need of a suggestion for how to calculate a column on base of the comparison of previous rows of other columns.

 

My data set is as follows, what I need to calculate is

 - "(net) Comm Cons": this column should contain the difference when column "Comm.Cons" changes value

 - "Released, Q, H": contains the cummulate sum of "Qty on hand" but, when "Comm.Cons" changes value, the cummulative sum should restart from the current row.

 

any help will be much appreciated

 

Qty on handDateComm. Cons(net) Comm ConsReleased, Q, HQty Expired less consumption
     corrected
110/32/22  11
110/32/22  22
307/31/2023773225
67/31/2023773831
207/31/2023775851
207/31/2023777871
207/31/2023779891
137/31/202377111104
24/30/202581742104
484/30/2025817450104
54/30/2025817455104
484/30/20258174103133
109/30/20251001910133
109/30/20251001920134
  • Hi,

    This calculated column formula works provided the entries in the "Comm. Cons" column are in ascending order.

    (net) Comm. Cons = [Comm. Cons]-CALCULATE(MAX(Data[Comm. Cons]),FILTER(Data,Data[Date]<EARLIER(Data[Date])))

    Hope this helps.

     

6 Replies

    • Anonymous's avatar
      Anonymous
      Not applicable

      am looking to a way to calculate in DAX

       

      currently, I set those codes:

      Comm.Cons(net) = 

      CALCULATE(SUM('ShortageReport'[Ordered, Quantity]),
      FILTER(ShortageReport, ShortageReport[RM / WIP Item Number] = StockReport[ITEM] && ShortageReport[Start Date] <= 'StockReport'[EXPIRY DATE]),
      USERELATIONSHIP(ShortageReport[RM / WIP Item Number], 'StockReport'[ITEM]))
       
      Released Q,H = CALCULATE(SUM('StockReport'[QTY ON HAND]), FILTER(StockReport, StockReport[ITEM] = Earlier(StockReport[ITEM]) && StockReport[Index] <= EARLIER(StockReport[Index])))
       
      but both are not working as I cannot look into the value of previous row
      • Ashish_Mathur's avatar
        Ashish_Mathur
        Super User

        Hi,

        This calculated column formula works provided the entries in the "Comm. Cons" column are in ascending order.

        (net) Comm. Cons = [Comm. Cons]-CALCULATE(MAX(Data[Comm. Cons]),FILTER(Data,Data[Date]<EARLIER(Data[Date])))

        Hope this helps.