Forum Discussion
SAM190370
9 years agoFrequent Visitor
cursive calculation forecast
Hi, Can I do something like this in dax or powerquery? The formular should calculate the forecast using previous months sales and previous month forecast. If no sales in previous month it sh...
- 9 years ago
This might work:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQwMFCK1QEyjGAMUyjDCCalgI2MBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Sales = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Sales", type number}}), AddIndex = Table.Buffer(Table.AddIndexColumn(#"Changed Type", "Row", 1, 1)), ListGenerate = List.Generate(()=> [Counter=1, Forecast=AddIndex[Sales]{0}], each [Counter] <=Table.RowCount(AddIndex), each [Forecast = if AddIndex{[Row=Counter]}[Sales]<>null then [Forecast]*0.7+AddIndex{[Row=Counter-1]}[Sales]*0.3 else [Forecast], Counter = [Counter]+1 ] ), Forecast = Table.FromRecords(ListGenerate), #"Merged Queries" = Table.NestedJoin(AddIndex,{"Row"},Forecast,{"Counter"},"Forecast.1",JoinKind.LeftOuter), #"Expanded Forecast.1" = Table.ExpandTableColumn(#"Merged Queries", "Forecast.1", {"Forecast"}, {"Forecast"}) in #"Expanded Forecast.1"
SAM190370
9 years agoFrequent Visitor
Hi ImkeF
Thanks a lot. This is indeed very close. Just one thing. In my example in row 6 we do not have the same result.
Maybe you have an idea how to fix this?
/ Søren
SAM190370
9 years agoFrequent Visitor
Hi Imke,
I was able to made the change myself and have accepted your solution. Thanks again.
/ Søren