Forum Discussion

nardcox's avatar
nardcox
Frequent Visitor
3 years ago

DAX Calculate Inventory Expiry Risk

I've been searching a lot but can't seem to find an answer. I'll try to keep it brief, concise and complete.

  • I work in a warehouse
  • We store goods on locations
  • Some of these goods have an expiry date
  • I want to calculate what the risk of expiring is for these items per location

Sound simple enough right, but

  • We have a fix sequence of locations that this stock will be allocated, so I have to take that into account

Example data for a single item

Sales Qty per day: 2,43 
SequenceExp DateStock Qty

Expiry Qty

(Desired output)

128.02.20231190
231.05.20231210
331.05.2023806620
430.06.2023420
528.02.2023372372
631.05.2023810810
728.02.2023218218
830.06.2023928898

 

I can't get the table looking properly so I've added a prntscrn below as well.

 

 

Really hoping someone can help. The closest I've gotten was this, the last qty (631) is incorrect.

Maybe the formula was just lucky getting the rest correct, haven't checked my other examples yet.

Old Exp Stock Qty =
var days_till_today = stock_exp[Date]-today()
var days_between_dates = MAX(0,DATEDIFF(LOOKUPVALUE(stock_exp[Date],Stock_exp[Sequence],Stock_exp[Sequence]-1),stock_exp[Date],DAY))
var daily_sales = 2+(43/100)
var cum_physical = CALCULATE(SUM(Stock_exp[Stock]),FILTER(Stock_exp,stock_exp[sequence]<=EARLIER(Stock_exp[Sequence])))
var cum_sales = days_till_today*daily_sales
return
IF(Stock_exp[Sequence]=1,
    MAX(0, ROUNDDOWN( stock_exp[Stock] - cum_sales , 0) ),
    MAX(0,
        ROUNDDOWN(
            MIN( cum_physical - cum_sales ,
                stock_exp[Stock] - days_between_dates * daily_sales )
                ,0)
        )
    )
 
 
 
EDIT: I just found this topic, gonna read up on it now...
EDIT: Unfortunately no solution in the above topic, it was also slightly simpeler because that one works FEFO which I don't 😞
EDIT: Neither in any of the following topics

13 Replies