Advertisement
DVL00

PQ Error 2

Mar 3rd, 2023 (edited)
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. let
  2.  
  3. //Change next line to reflect actual data source
  4.  
  5. Source = Production,
  6. #"Changed Type" = Table.TransformColumnTypes(Source,{ {"StoreNumber", Int64.Type}, {"StoreName", type text}, {"DepartmentName", type text}, {"WeekEnding", type date}, {"Week", Int64.Type}, {"Year", Int64.Type}, {"EndingInventoryAmount", Int64.Type}}),
  7.  
  8. /*If data not sorted as per your example add a sorting step here*/
  9.  
  10. //Add Index for subsequent sorting
  11.  
  12. #"Added Index" = Table.AddIndexColumn(#"Changed Type", "Index", 0, 1, Int64.Type),
  13.  
  14. //group by StoreNumber, StoreName and DepartmentName
  15.  
  16. //then add aggregation with a shifted EndingInventoryAmount column
  17.  
  18. //which would be the Beg_Inv for that row
  19.  
  20. #"Grouped Rows" = Table.Group(#"Added Index", {"StoreNumber", "StoreName", "DepartmentName"}, { {"Starting", (t)=>Table.FromColumns( Table.ToColumns(t) & {{null} & List.RemoveLastN(t[EndingInventoryAmount],1)}, type table [StoreNumber=nullable number, StoreName=nullable text, DepartmentName=nullable text, WeekEnding=nullable date, Week=nullable number, Year=nullable number, EndingInventoryAmount=nullable number, Index=number, Beg_Inv=number])}}),
  21.  
  22. //Expand the subtables
  23.  
  24. #"Expanded Starting" = Table.ExpandTableColumn(#"Grouped Rows", "Starting", {"WeekEnding", "Week", "Year", "EndingInventoryAmount", "Index", "Beg_Inv"}),
  25.  
  26. //Sort back to original order
  27.  
  28. //Then remove the Index column and set the data types
  29.  
  30. #"Sorted Rows" = Table.Sort(#"Expanded Starting",{{"Index", Order.Ascending}}), #"Removed Columns" = Table.RemoveColumns(#"Sorted Rows",{"Index"}), #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"StoreNumber", Int64.Type}, {"StoreName", type text}, {"DepartmentName", type text}, {"WeekEnding", type date}, {"Week", Int64.Type}, {"Year", Int64.Type}, {"EndingInventoryAmount", Int64.Type}, {"Beg_Inv", Int64.Type}}) in #"Changed Type1"
  31.  
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement