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

Join the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now

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
April Power BI Update Carousel

Power BI Monthly Update - April 2026

Check out the April 2026 Power BI update to learn about new features.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

FabCon and SQLCon Highlights Carousel

FabCon &SQLCon Highlights

Experience the highlights from FabCon & SQLCon, available live and on-demand starting April 14th.