Forum Discussion
Insert Rows for Missing Values of a Column
- 1 year ago
ryan_mayu
This works!
But since I have millions of row in the table, is there a way to do it in a single query without the merging of tables?
I believe the merge will slow load time.
Maybe a group within a group, then expand out to reveal the full sequence.
Something like this, but haven't got it to work yet.: - 1 year ago
I think we have to merge tables However, this time we don't create a new table
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlDSUTI0BhIGUGyoFKsDFTbFLmyBVdjIALuwEXZDjOBCWK1EEzbHLmyBVdjIAFU4FgA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t, Sequence = _t, Sub = _t, Sub1 = _t, Value = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Sequence", Int64.Type}}),
Custom1 = Table.Group(#"Changed Type" , {"Sub1"}, {{"column", each {List.Min([Sequence])..List.Max([Sequence]) }}}),
Table = Table.ExpandListColumn(Custom1, "column"),
Custom2 = Table.NestedJoin(Table, {"Sub1", "column"}, #"Changed Type", {"Sub1", "Sequence"}, "Table", JoinKind.LeftOuter),
#"Expanded Table" = Table.ExpandTableColumn(Custom2, "Table", {"ID", "Sub", "Value"}, {"ID", "Sub", "Value"}),
#"Filled Down" = Table.FillDown(#"Expanded Table",{"ID", "Sub", "Value"}),
#"Sorted Rows" = Table.Sort(#"Filled Down",{{"Sub1", Order.Ascending}, {"column", Order.Ascending}})
in
#"Sorted Rows"pls see the attachment below
you can try this
let
Source = Table,
#"Grouped Rows" = Table.Group(Source, {"Sub1"}, {{"column", each {List.Min([Sequence])..List.Max([Sequence]) }}}),
#"Expanded column" = Table.ExpandListColumn(#"Grouped Rows", "column"),
#"Merged Queries" = Table.NestedJoin(#"Expanded column", {"Sub1", "column"}, Table, {"Sub1", "Sequence"}, "Table", JoinKind.LeftOuter),
#"Expanded Table" = Table.ExpandTableColumn(#"Merged Queries", "Table", {"ID", "Sub", "Value"}, {"ID", "Sub", "Value"}),
#"Filled Down" = Table.FillDown(#"Expanded Table",{"ID", "Sub", "Value"})
in
#"Filled Down"
pls see the attachment below