Forum Discussion
SpreadsheetNerd
1 year agoRegular Visitor
Suggestions for Measure Optimisation
Howdy! Long time lurker, first time poster. Normally, I have absolutely no issues googling all your helpful suggestions and figuring out my own DAX challenges; I can't say I've ever been truely...
shafiz_p
Super User
1 year agoHi SpreadsheetNerd Try this:
WeeksOfSupply =
VAR CurrentSOH = [Closing SOH Quantity]
VAR MaxDate = MAX('Date'[Date])
VAR FutureWeeksTable = CALCULATETABLE(VALUES('Date'[Week Ending]), 'Date'[Date] > MaxDate)
VAR OOSWeek =
MINX(
FILTER(
FutureWeeksTable,
CALCULATE(SUM('Date'[Date]), 'Date'[Date] <= EARLIER('Date'[Week Ending])) > CurrentSOH
),
'Date'[Week Ending]
)
VAR WeeksSupply =
SWITCH(
TRUE(),
ISBLANK(OOSWeek), BLANK(),
CurrentSOH = BLANK(), BLANK(),
CurrentSOH < 0, 0,
NOT(ISBLANK(OOSWeek)),
VAR FutureDemandExhaustionWeek =
CALCULATE(
[Demand Quantity],
'Date'[Date] <= OOSWeek,
'Date'[Date] > MaxDate
)
VAR ExcessDemand = FutureDemandExhaustionWeek - CurrentSOH
VAR DemandInExhaustionWeek =
CALCULATE([Demand Quantity], OOSWeek, REMOVEFILTERS('Date'))
VAR PartDays = DIVIDE(FutureDemandExhaustionWeek - ExcessDemand, DemandInExhaustionWeek)
RETURN OOSWeek - MaxDate - 1 + PartDays,
999
)
RETURN DIVIDE(WeeksSupply, 7, BLANK())
Hope this helps!!
If this solved your problem, please accept it as a solution and a kudos!!
Best Regards,
Shahariar Hafiz