Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

Reply
MrJayDee
Regular Visitor

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
1 ACCEPTED SOLUTION
Irwan
Super User
Super User

Hello @MrJayDee 

 

please check if this accomodate your need.

Irwan_0-1719975298995.png

 

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.

View solution in original post

1 REPLY 1
Irwan
Super User
Super User

Hello @MrJayDee 

 

please check if this accomodate your need.

Irwan_0-1719975298995.png

 

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.

Helpful resources

Announcements
May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.