Hi @nico (REVISED FOR WORKOUT PART TWO, SEE BELOW NEW POST)
It is possible to make the desired calculation completely out of measures, without the need of a calculated table, with a very acceptable speed.
Concept of a possible workout is first determine the current stock level as per today and secondly determine the net stock movement till the lead time. If the stock level plus the net stock movement till the lead time is negative, warn the purchase department, this reporting process is done on a daily base.
The past can not be changed, the purchase department can only act upon available forecast information as from today.
Could you comment if this concept-interpretation is correct and if the the work-out meets your information requirements ?
PBIX attached : REVISED FOR WORKOUT PART TWO; SEE NEXT POST BELOW
Purch Dashboard EDNA v8.pbix (510.7 KB)
Workout part one : determine current stock level as per today
Determine actual stock level ( on a daily base) can be done by taking the current stock level, deduct the cumulative stock movements till yesterday and add back the cumulative stock movements.
Measures as follows:
OHQ = SUM(‘All items’[ONHAND])
Cum Stockmvt till yesterday = //results in a fixed cumulative movement over all days till yesterday
Var StockYesterday = CALCULATE( [Stockmvmt Order - WO],
FILTER( ALLSELECTED(DateLT[Date]), DateLT[Date] <= TODAY() - 1)) // yesterday )))
Return
IF( ISBLANK([Stockmvmt Order - WO]), BLANK(), StockYesterday)
Cum Stockmvt =
Var CumStockMvmt = CALCULATE( [Stockmvmt Order - WO],
FILTER( ALLSELECTED(DateLT[Date]), DateLT[Date] <= MAX( DateLT[Date])))
Note 1: cumulative values will appear when using MAX at "FILTER( ALLSELECTED(DateLT[Date]), DateLT[Date] <= MAX( DateLT[Date]))) ", when using specific date values, like TODAY(), the same cumulative value till the specific date value is calculated for every single row/date ( see also picture 1 below at “Cum Stockmvt till yesterday”
Note 2: the original stock calculation “Cumulated OHQ” does not exclude the stock movement till today, this must be excluded as the stock level of today already includes the stock mutations till today.
Note 3: the data model is not changed, it is important that all date keys have date values (not text values)
Note 4: the measures used can be found in the measure group DS Stock Today Calc, an example can be seen below of Product 1018, and in the PBIX file, page 1.
Workout part two : determine next stock movement till lead time, check daily if out of stock
Obviously the Out of stock estimation highly depends on the accuracy of the forecast of stock PO and stock WO.
- As the lead time stock movement table does not have a date (and missing date context) the Stock End of Day Today is not correct in “Purch Dashboard EDNA v8.pbix” , this is corrected in next post below and should be derived of the original OHQ, from the All Items table, assumed it is representing the stock at the end of each day and refreshed on a daily base (!).
The correct DAX formula should be just the stock as per today:
OHQ (Stock EoToday) =
Var OHQty = SUM('All items'[ONHAND])
Determine the net stock movement till lead time:
Cum Stockmvt tomorrow till lead day = //results in cumulative stock movements from today End of Day till the Lead Time in days in the future
Var CumStockMvmtToday = CALCULATE( [Stockmvmt Order - WO],
FILTER( ALLSELECTED(DateLT[Date]), DateLT[Date] <= TODAY() )) // End of Day today )))
Var LeadTime = SELECTEDVALUE( 'All Items'[Lead TIme])
Var CumStockMvmtLeadTime = CALCULATE( [Stockmvmt Order - WO],
FILTER( ALLSELECTED(DateLT[Date]), DateLT[Date] <= TODAY() + LeadTime)) // today + lead time in days in the future )))
Var StockmvmtTillLeadDay = CumStockMvmtLeadTime - CumStockMvmtToday
Return
IF( ISBLANK([Stockmvmt Order - WO]), BLANK(), StockmvmtTillLeadDay)
If the current stock level and the stock movement till the lead time is negative, a warning is sent to the purchase department, triggered by a base comparison measure, which could be further filtered:
Purchasing Warning = IF( [Expected Stock after Lead TimeTT] < 0, “Warn Purchase department”, BLANK())
Note: the majority of the Purchase warning messages appears by already negative current stock levels, what should not be possible, as inventory can not be negative. NOT CORRECT; CAUSED BY WRONG STOCK FORMULA
Two reports attached:
Report 1 Calculation of current stock level
Report 2 Expected stock level per end of the lead time, with some purchase warnings
`
Could you comment if the concept and the work-out meet your information requirements ?
Kind regards, Delta Select