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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

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
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors