Forum Discussion
Creating multiple date tables in one table
- 6 years ago
Hi , Anonymous
Click New source ->create a blank query->advanced Editor
Then paste following M code:
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTLUN9Q3MjC0BDGN9I2hnFidaCUnoJAppqyRAVjWGbteqKwLUMhc38gIJm2qb2SJkHXFK+uGJovmLHe8mj3wynrilfXCK+uNWzYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Phase = _t, start = _t, end = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Phase", type text}, {"start", type date}, {"end", type date}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Duration.TotalDays(Date.StartOfDay([end])-Date.StartOfDay([start]))), #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each List.Generate(()=>[Custom], each _ >= 0, each _ - 1)), #"Expanded Custom.1" = Table.ExpandListColumn(#"Added Custom1", "Custom.1"), #"Added Custom2" = Table.AddColumn(#"Expanded Custom.1", "Date", each if [Custom.1]=[Custom] then [start] else Date.AddDays(Date.StartOfDay([start]),[Custom]-[Custom.1])), #"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"start", "end", "Custom", "Custom.1"}), #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"Date", type date}}), #"Sorted Rows" = Table.Sort(#"Changed Type1",{{"Phase", Order.Ascending}, {"Date", Order.Ascending}}) in #"Sorted Rows"For more detail, please double click the step in "APPLIED STEPS".
Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi , Anonymous
Click New source ->create a blank query->advanced Editor
Then paste following M code:
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WclTSUTLUN9Q3MjC0BDGN9I2hnFidaCUnoJAppqyRAVjWGbteqKwLUMhc38gIJm2qb2SJkHXFK+uGJovmLHe8mj3wynrilfXCK+uNWzYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Phase = _t, start = _t, end = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Phase", type text}, {"start", type date}, {"end", type date}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each Duration.TotalDays(Date.StartOfDay([end])-Date.StartOfDay([start]))),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each List.Generate(()=>[Custom], each _ >= 0, each _ - 1)),
#"Expanded Custom.1" = Table.ExpandListColumn(#"Added Custom1", "Custom.1"),
#"Added Custom2" = Table.AddColumn(#"Expanded Custom.1", "Date", each if [Custom.1]=[Custom] then [start] else Date.AddDays(Date.StartOfDay([start]),[Custom]-[Custom.1])),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom2",{"start", "end", "Custom", "Custom.1"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"Date", type date}}),
#"Sorted Rows" = Table.Sort(#"Changed Type1",{{"Phase", Order.Ascending}, {"Date", Order.Ascending}})
in
#"Sorted Rows"For more detail, please double click the step in "APPLIED STEPS".
Best Regards,
Community Support Team _ Eason
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Anonymous6 years agoNot applicable
Brilliant! it took a bit of fiddling with the advanced editor to adjust the source data, but it seems to work perfectly now.
Thanks!