itsnotaboutthecell

Power Query M - Table: totalSales

Feb 22nd, 2018
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. /*
  2. Created By: Alex Powers
  3. Website: http://www.itsnotaboutthecell.com
  4. LinkedIn: https://www.linkedin.com/in/alexmpowers/
  5. */
  6.  
  7. let
  8. itemsSold = #table(
  9. type table [Index = number, Item = text],
  10. {
  11. {1, "Pencil"},
  12. {2, "Paper"},
  13. {3, "Pen"},
  14. {4, "Notebook"},
  15. {5, "Eraser"}
  16. }
  17. ),
  18. Source = #date(2010,1,1),
  19. TotalDays = Duration.Days(Date.From(DateTime.LocalNow()) - Source),
  20. #"Custom: List of Dates" = List.Dates(Source, TotalDays, #duration(1,0,0,0)),
  21. #"Converted to Table" = Table.FromList(#"Custom: List of Dates", Splitter.SplitByNothing(), type table [Date = date], null, ExtraValues.Error),
  22. #"Custom List: Random Date Values" = Table.AddColumn(#"Converted to Table", "List of Dates", each {0..Number.RoundDown(Number.RandomBetween(100, 200))}, type list),
  23. #"Buffer: Random Date Values" = Table.Buffer(#"Custom List: Random Date Values"),
  24. #"Expanded List of Dates" = Table.ExpandListColumn(#"Buffer: Random Date Values", "List of Dates"),
  25. #"Custom: Random Sales" = Table.AddColumn(#"Expanded List of Dates", "Sales", each Number.RandomBetween(10000, 50000), type number),
  26. #"Buffer: Random Sales" = Table.Buffer(#"Custom: Random Sales"),
  27. #"Custom: Index" = Table.AddColumn(#"Buffer: Random Sales", "Index", each Int8.From(Number.RandomBetween(1, 5)), type number),
  28. #"Buffer: Index" = Table.Buffer(#"Custom: Index"),
  29. #"Merged Queries" = Table.NestedJoin(#"Buffer: Index",{"Index"},itemsSold,{"Index"},"Item Lookup",JoinKind.Inner),
  30. #"Expanded Item Lookup" = Table.ExpandTableColumn(#"Merged Queries", "Item Lookup", {"Item"}, {"Item"}),
  31. #"Removed Columns" = Table.RemoveColumns(#"Expanded Item Lookup",{"List of Dates", "Index"})
  32. in
  33. #"Removed Columns"
Advertisement
Add Comment
Please, Sign In to add comment