Forum Discussion

MrJayDee's avatar
MrJayDee
Regular Visitor
2 years ago
Solved

Subtract values based off date

Hello,

 

I am trying to write a formula that calculates remaining inventory based off a ship date and I am about to rage quit because I cannot figure it out! This is my current formula and its not working the way I need it to:

 

Remaining Inv = 'Working Page'[On Hand]
-MAXX(TOPN(1,FILTER('Working Page','Working Page'[ID]=EARLIER('Working Page'[ID])&&'Working Page'[Ship Date]<EARLIER('Working Page'[Ship Date])),'Working Page'[Ship Date]),'Working Page'[Order Qty])

 

I need a column that takes the On hand inventory and subtracts the qty ordered based off date. However, the issue is its taking the total On hand rather than the difference from the previous ship date. The results I am looking for are in the Remaining Inv. 

 

IDOn HandItem NameDescriptionOrder QtyLocationShip ToIndexShip DateRemaining Inv
Item1Location123139Item1RB100Location1Customer 117/2/202423039
Item1Location123139Item1RB100Location1Customer 227/3/202422939
Item1Location123139Item1RB100Location1Customer 337/3/202422839
Item1Location123139Item1RB200Location1Customer 447/3/202422639
Item1Location123139Item1RB100Location1Customer 557/5/202422539
Item1Location123139Item1RB300Location1Customer 667/5/202422239
Item1Location123139Item1RB200Location1Customer 777/23/202422039
Item1Location123139Item1RB1300Location1Customer 887/24/202420739
Item1Location123139Item1RB2100Location1Customer 997/24/202418639
Item1Location123139Item1RB800Location1Customer 10107/24/202417839
Item1Location123139Item1RB1400Location1Customer 11117/24/202416439
Item1Location123139Item1RB2100Location1Customer 12127/24/202414339
  • Hello MrJayDee 

     

    please check if this accomodate your need.

     

    Remaining Inv =
    var _PreviousSum =
    SUMX(
        FILTER(
            'Table',
            'Table'[Index]<EARLIER('Table'[Index])
        ),
        'Table'[Order Qty]
    )
    Return
    'Table'[On Hand]-'Table'[Order Qty]-_PreviousSum
     
    The idea of this result is :
    1. _PreviousSum is used for finding sum value of previous index (that 'Index' column is great on finding previous sum value).
    2. substract 'On Hand' column with 'Order Qty' then substract again previous sum value (since _PreviousSum only calculate previous index, current index is not calculated)
     
    Hope this will help you.
    Thank you.

1 Reply

  • Hello MrJayDee 

     

    please check if this accomodate your need.

     

    Remaining Inv =
    var _PreviousSum =
    SUMX(
        FILTER(
            'Table',
            'Table'[Index]<EARLIER('Table'[Index])
        ),
        'Table'[Order Qty]
    )
    Return
    'Table'[On Hand]-'Table'[Order Qty]-_PreviousSum
     
    The idea of this result is :
    1. _PreviousSum is used for finding sum value of previous index (that 'Index' column is great on finding previous sum value).
    2. substract 'On Hand' column with 'Order Qty' then substract again previous sum value (since _PreviousSum only calculate previous index, current index is not calculated)
     
    Hope this will help you.
    Thank you.