Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
ELOO
Frequent 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 second column should the be null

1x
2y
3z
5a
6b
8c

Can You help me? 

thanks

ELOO

 

3 REPLIES 3
AlienSx
Super User
Super User

Hi, @ELOO 

// suppose you have a table "your_table" with Column1 and Column2
let
    Source = your_table,
    table_numbers = Source[Column1],
    all_numbers = List.Buffer({List.Min(table_numbers)..List.Max(table_numbers)}),
    diff = List.Buffer(List.Difference(all_numbers, table_numbers)),
    out = 
        Table.FromRows(
            List.Combine(
                {Table.ToRows(Source), 
                List.Transform(diff, (x) => {x, null})}
            )
        )
in
    out
PhilipTreacy
Super User
Super User

Hi @ELOO 

 

Download example PBIX file

 

I started with this table

filln1.png

 

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"}),

 

filln2.png

 

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"})

 

filln3.png

 

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



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi Phil, thanks for your reply, can you help me with the hand coding, I tried it myself but unsuccessfull thanks

ELOO

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors