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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
Anonymous
Not applicable

Remove duplicates but keep nulls

I am having an issue while attempting to remove duplicates but keeping nulls. The ID column has both duplicates and nulls. I need to remove the duplicate values but keep the null IDs. I am trying to do this within an Append table. The IDs with nulls are coming from a budget table. 

 

Thanks!

1 ACCEPTED SOLUTION
dufoq3
Community Champion
Community Champion

let
    Source = Table.Combine({Master, Budget}),
    ChangedType = Table.TransformColumnTypes(Source,{{"ID", type text}}),
    GroupedRows = Table.Group(ChangedType, {"ID"}, {{"T", each if [ID]{0} = null then _ else Table.FirstN(_, 1), type table}}),
    CombinedT = Table.Combine(GroupedRows[T])
in
    CombinedT

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

View solution in original post

9 REPLIES 9
ronrsnfld
Super User
Super User

Since you chose not to share sample data, here is an example with a one column table of ID's.

You should be able to adapt it to your actual data set.

It makes use of the fact that List.Distinct has an optional Equation Criteria:

If ID is not the first column, change the Index {0} to reflect its location

 

let
    Source = Table.FromColumns(
        {{"ab","cd",null,null,"ef","ab", "gh", null,"ij"}},
         type table[ID=nullable text]),
         
    x =Table.FromRows(List.Distinct(Table.ToRows(Source),each if _{0}=null then Text.NewGuid() else _{0}))

in
    x

 

 

Source

ronrsnfld_0-1738873240649.png

 

De-Duped

ronrsnfld_1-1738873280324.png

 

 

dufoq3
Community Champion
Community Champion

Hi, provide sample data and expected result please.


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Anonymous
Not applicable

Sample File: https://drive.google.com/file/d/1Pd7K4vw-cZzD1CG-ITmUrfXiO8e3nSXt/view?usp=drive_link

I need the ID column in the Append table to remove duplicates while keeping all the nulls.

 

dufoq3
Community Champion
Community Champion

Output

dufoq3_0-1738870306020.png

 

Select Append1 query. Open advanced editor. Replace whole code with this one:

let
    Source = Table.Combine({Master, Budget}),
    ChangedType = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}}),
    GroupedRows = Table.Group(ChangedType, {"ID"}, {{"T", each if [ID]{0} = null then _ else Table.FirstN(_, 1), type table}}),
    CombinedT = Table.Combine(GroupedRows[T])
in
    CombinedT

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Anonymous
Not applicable

In my actual file (not the test), the ID column is text. It looks like this "123.456.789". I believe this is giving the code issues.

dufoq3
Community Champion
Community Champion

let
    Source = Table.Combine({Master, Budget}),
    ChangedType = Table.TransformColumnTypes(Source,{{"ID", type text}}),
    GroupedRows = Table.Group(ChangedType, {"ID"}, {{"T", each if [ID]{0} = null then _ else Table.FirstN(_, 1), type table}}),
    CombinedT = Table.Combine(GroupedRows[T])
in
    CombinedT

Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Anonymous
Not applicable

Thank you. Another issue is in my actual file the column known as "ID" is actually named "CER #". How would this change the code?

Anonymous
Not applicable

I was able to find a work around by changing the column name to just "CER".

dufoq3
Community Champion
Community Champion

If you need further assistance, provide sample data again with full description that covers your issue and don't forget to provide also expected result based on sample data.

 

 

let
    Source = Table.Combine({Master, Budget}),
    ChangedType = Table.TransformColumnTypes(Source,{{"CER #", type text}}),
    GroupedRows = Table.Group(ChangedType, {"CER #"}, {{"T", each if [#"CER #"]{0} = null then _ else Table.FirstN(_, 1), type table}}),
    CombinedT = Table.Combine(GroupedRows[T])
in
    CombinedT

 


Note: Check this link to learn how to use my query.
Check this link if you don't know how to provide sample data.

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

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.