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
Dicken
Continued Contributor
Continued Contributor

Merge columns keep null


Hi, if I have columns with nulls and want to merge   can I retian the null values where both columns contian nulls 
example ; 

let
  Source = #table(
    type table [Text = Any.Type, Text2 = Any.Type],
    {{"a", "b"}, {"b", null}, {null, null}, {"c", "e"}, {null, null}, {"d", "d"}}
  ),
  #"Merged Columns" = Table.CombineColumns(
    Source,
    {"Text", "Text2"},
    Combiner.CombineTextByDelimiter(""),
    "Merged"
  )
in
  #"Merged Columns"


so where both are null  show null ?   

Richard 

2 ACCEPTED SOLUTIONS
Jai-Rathinavel
Super User
Super User

Hi @Dicken  

To make sure null values remain unchanged when both columns contain null, you can adjust your approach with conditional logic. Try the below M code it should work !

let
    Source = #table(
        type table [Text = Any.Type, Text2 = Any.Type],
        {{"a", "b"}, {"b", null}, {null, null}, {"c", "e"}, {null, null}, {"d", "d"}}
    ),
    #"Merged Columns" = Table.AddColumn(Source, "Merged", each 
        if [Text] = null and [Text2] = null then null 
        else Text.Combine({[Text], [Text2]}, "")
    )
in
    #"Merged Columns"

 

Output:

JaiRathinavel_0-1748114801466.png

 

Appreciate a Kudos 👍 

 

Thanks,

Jai Rathinavel | LinkedIn

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

rohit1991
Super User
Super User

Hi @Dicken ,

Yes, it’s absolutely possible to retain null values when both columns contain null while merging in Power Query. The default Table.CombineColumns function doesn't differentiate between actual nulls and empty strings, so it will merge even two nulls into an empty string, which may not be what you want. To preserve null in cases where both columns are null, you can use a conditional column instead. This approach checks if both source columns are null, and if so, sets the result to null; otherwise, it combines the values. This gives you full control and preserves data integrity in scenarios like yours.

 

Here’s how you can implement it:

let
Source = #table(
type table [Text = Any.Type, Text2 = Any.Type],
{{"a", "b"}, {"b", null}, {null, null}, {"c", "e"}, {null, null}, {"d", "d"}}
),
#"Merged Columns" = Table.AddColumn(Source, "Merged", each
if [Text] = null and [Text2] = null then null
else Text.Combine({[Text], [Text2]}, "")
)
in
#"Merged Columns"

 


Did it work? ✔ Give a Kudo • Mark as Solution – help others too!

View solution in original post

4 REPLIES 4
slorin
Super User
Super User

Hi @Dicken 

with Table.CombineColumns

 

= Table.CombineColumns(
Source,
{"Text", "Text2"},
each if List.NonNullCount(_)>0 then Text.Combine(_) else null,
"Merged"
)

Stéphane 

rohit1991
Super User
Super User

Hi @Dicken ,

Yes, it’s absolutely possible to retain null values when both columns contain null while merging in Power Query. The default Table.CombineColumns function doesn't differentiate between actual nulls and empty strings, so it will merge even two nulls into an empty string, which may not be what you want. To preserve null in cases where both columns are null, you can use a conditional column instead. This approach checks if both source columns are null, and if so, sets the result to null; otherwise, it combines the values. This gives you full control and preserves data integrity in scenarios like yours.

 

Here’s how you can implement it:

let
Source = #table(
type table [Text = Any.Type, Text2 = Any.Type],
{{"a", "b"}, {"b", null}, {null, null}, {"c", "e"}, {null, null}, {"d", "d"}}
),
#"Merged Columns" = Table.AddColumn(Source, "Merged", each
if [Text] = null and [Text2] = null then null
else Text.Combine({[Text], [Text2]}, "")
)
in
#"Merged Columns"

 


Did it work? ✔ Give a Kudo • Mark as Solution – help others too!
Dicken
Continued Contributor
Continued Contributor

Thank you, 

Jai-Rathinavel
Super User
Super User

Hi @Dicken  

To make sure null values remain unchanged when both columns contain null, you can adjust your approach with conditional logic. Try the below M code it should work !

let
    Source = #table(
        type table [Text = Any.Type, Text2 = Any.Type],
        {{"a", "b"}, {"b", null}, {null, null}, {"c", "e"}, {null, null}, {"d", "d"}}
    ),
    #"Merged Columns" = Table.AddColumn(Source, "Merged", each 
        if [Text] = null and [Text2] = null then null 
        else Text.Combine({[Text], [Text2]}, "")
    )
in
    #"Merged Columns"

 

Output:

JaiRathinavel_0-1748114801466.png

 

Appreciate a Kudos 👍 

 

Thanks,

Jai Rathinavel | LinkedIn

 




Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





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.