Forum Discussion
ELOO
3 years agoFrequent Visitor
add missing rows and add null value
Hi I have a table with two columns, the firs column are consecutive numbers, however some numbers are missing. I want to add in power query editor row for all missing number, the value in the sec...
PhilipTreacy
3 years agoSuper User
Hi ELOO
I started with this table
Using this code
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMlTSUapQitWJVjICsirBLGMgqwrMMgWyEsEsMyArCcyyALKSlWJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Value = _t, Letter = _t]),
NewTable = Table.FromList({List.Min(Source[Value])..List.Max(Source[Value])}, null, {"Value"}),
#"Merged Queries" = Table.NestedJoin(NewTable, {"Value"}, Source, {"Value"}, "NewTable", JoinKind.LeftOuter),
#"Expanded NewTable" = Table.ExpandTableColumn(#"Merged Queries", "NewTable", {"Letter"}, {"Letter"})
in
#"Expanded NewTable"
How this works is that it takes the table in Source and creates a new table in the NewTable step (this is hand coded) that is a single column consisting of all values between the min and max from the Values column in the Source table
NewTable = Table.FromList({List.Min(Source[Value])..List.Max(Source[Value])}, null, {"Value"}),
You then do a table join on the on the Newtable and the Source table (again hand coded).
#"Merged Queries" = Table.NestedJoin(NewTable, {"Value"}, Source, {"Value"}, "NewTable", JoinKind.LeftOuter),
You can then expand the column created by that join to give this
#"Expanded NewTable" = Table.ExpandTableColumn(#"Merged Queries", "NewTable", {"Letter"}, {"Letter"})
You'll need to do a bit of hand coding in the Advanced Editor to get this to work in your situation. Happy to assist you if you post your full query here.
Regards
Phil
- ELOO2 years agoFrequent Visitor
Hi Phil, thanks for your reply, can you help me with the hand coding, I tried it myself but unsuccessfull thanks
ELOO