Forum Discussion
Anonymouspanda
7 years agoRegular Visitor
Forecasting on weekly basis
Hi everyone, I have an issue about doing a loop by using DAX language. I need to calculate the opening and closing stock for forecasting of each material in every week. For instance, the openin...
- 7 years ago
Are you looking for this?
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUXIEYgMgNlWK1YlWMoKKgGSMwSLGUBEjsDqQCEjOCUXECCpiABaF6YKJGMN1OQOxCVyNEVTEFG6OMVTEECISCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Week = _t, Material = _t, Out = _t, In = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Week", Int64.Type}, {"Out", Int64.Type}, {"In", Int64.Type}, {"Material", type text}}), #"Grouped Rows" = Table.Group(#"Changed Type", {"Material"}, {{"AD", each _, type table}}), #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each let Source=[AD], In_Out= Table.AddColumn(Source,"In-Out", each [In]-[Out]), X=List.Skip(List.Accumulate(In_Out[#"In-Out"],{0},(state,current)=>state&{List.Last(state)+current})), Y= Table.FromColumns(Table.ToColumns(In_Out)&{X}), Z= Table.AddColumn(Y,"OB", each [Column6]-[Column4]+[Column3]), #"Renamed Columns" = Table.RenameColumns(Z,{{"Column1", "Week"}, {"Column2", "Material"}, {"Column3", "Out"}, {"Column4", "In"}, {"Column6", "CB"}}), #"Removed Columns" = Table.RemoveColumns(#"Renamed Columns",{"Column5"}), #"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Week", "Material", "Out", "In", "OB", "CB"}) in #"Reordered Columns"), #"Removed Other Columns" = Table.SelectColumns(#"Added Custom",{"Custom"}), #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Other Columns", "Custom", {"Week", "Material", "Out", "In", "OB", "CB"}, {"Week", "Material", "Out", "In", "OB", "CB"}) in #"Expanded Custom"
Anonymouspanda
7 years agoRegular Visitor
Hi Cherie,
How to remove the table below, modify the code provided by smpa01, and get the values shown on the Opening Stock Column. Here is my original table for your reference.
v-cherch-msft
7 years agoMicrosoft Employee