Quantcast
Channel: SQLServerCentral » Data Warehousing » Analysis Services » Latest topics
Viewing all articles
Browse latest Browse all 1341

MDX Forecasting puzzle

$
0
0
Greetings MDXperts! I'm trying to forecast when we'll run out of inventory. I have an Analysis Services cube that has the following measures at the date (single day) level:[Measures].[Forecast Qty Sold] (going out 24 months into the future)[Measures].[End of period Qty] (this value for the current date is the current quantity on hand)I also have a Date Status attribute in the Date dimension. Dates in the past =1, today = 2, dates in the future = 0. It's updated nightly when the cube is reprocessed.So now I want to create a measure that has a single date value for each item number representing the day we'll run out of the current stock, i.e. the last date on which the quantity on hand exceeds the cumulative sum of forecast unit sales from current date to whatever date we run out. Here's how I solved the problem in SQL:[code="sql"]With ForecastAvail --Use windowing funciton to predict daily available qty based on current available qty and forecastas ( Select a.ItemID , ForecastDate , RemainQtyAvail = isnull( b.QtyInStock, 0) -SUM(a.Forecast) over (Partition by ItemID order by ForecastDate ) from Forecast a left outer join Inventory..Inventory (nolock) b on a.ItemID = b.ItemID )--Select last date where qty available exceeds cumulative forecast for each item--Use that date to calculate days and weeks of supplyselect ItemID , LastAvailDate = max( Case when RemainQtyAvail > 0 then ForecastDate else 0 end) , DaysOfSupply = datediff(dd, getdate(), max( Case when RemainQtyAvail > 0 then ForecastDate else 0 end)) , WeeksOfSupply = datediff(week, getdate(), max( Case when RemainQtyAvail > 0 then ForecastDate else 0 end))-1from ForecastAvail group by ItemID[/code]That yields results:[font="Courier New"]itemno LastAvail DaysOfSupply WeeksOfSupply102REDSOCK 4/13/2016 0:00 29 3102BLUSOCK 4/11/2016 0:00 27 3102YELSOCK 4/25/2016 0:00 41 5[/font]Unfortunately, with my meager MDX skills, I don't know how to approach this in an Analysis Services context. Any suggestions? Thanks!

Viewing all articles
Browse latest Browse all 1341

Trending Articles