Concatenate in Blank Fileds in Power Query

harishs

Board Regular
Joined
Jul 3, 2016
Messages
50
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi Team,

How do I Concatenate 3 columns, filling only in NULL/BLANK Cells of other column?

In a report we work, it has 'First Name', 'Middle Name', 'Last Name' and 'FULL NAME' columns
1. 'FULL NAME' already has information, however for few people there is no data, which will be NULL/BLANK.
2. I need to concatenate, 'First Name' & 'Middle Name' & 'Last Name' together to get 'FULL NAME'.
2a. This logic should be applied only in NULL/BLANK fields in 'FULL NAME' column.

Regards,
Harish S
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Using this sample data in an Excel Table named Table1
Code:
First        Middle   Last        Full
Alpha        J        Zero        Alpha Jan Zero
Bravo        F        Clark       Bravo F Clark
Charlie      Mar      Davis        
Delta        Apr      Hass        Delta A Hass
Echo         May      Forrest     Echo May Forrest
Foxtrot      Jun      Sage        Foxtrot Jun Sage
Golf         J        Berg
This query replaces nulls in the Full field with concatenated First, Middle and Last names.
Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    SetDataTypes = Table.TransformColumnTypes(Source,{{"First", type text}, {"Middle", type text}, {"Last", type text}, {"FullName", type text}}),
    ReplaceNulls = Table.ReplaceValue(SetDataTypes,null,each [First] & " " & [Middle] & " " & [Last],Replacer.ReplaceValue,{"FullName"})
in
    ReplaceNulls

These are the results:
Code:
First        Middle   Last        FullName
Alpha        J        Zero        Alpha Jan Zero
Bravo        F        Clark       Bravo F Clark
Charlie      Mar      Davis       [B]Charlie Mar Davis[/B]
Delta        Apr      Hass        Delta A Hass
Echo         May      Forrest     Echo May Forrest
Foxtrot      Jun      Sage        Foxtrot Jun Sage
Golf         J        Berg        [B]Golf J Berg[/B]

Is that something you can work with?
 
Last edited:
Upvote 0
Hi Ron,

Thanks a ton for the solution... working exactly the way it was expected.

One small upgrade is required (realised only after using the code given above).
In some cases, we found NULLs in Middle & Last Name... can we have the Nulls to be ignored in Concatenate?

I am very new to Power Query and this is my first attempt to create a database using Power Query hence this ask.

Regards,
Harish S
 
Upvote 0
Change this part
Code:
[COLOR=#333333][First] & " " & [Middle] & " " & [Last][/COLOR]
to this one
Code:
Text.Combine(List.RemoveNulls(Record.ToList(_)), " ")
 
Upvote 0
Slight enhancement to Bill's code...in case your data has other fields that you don't want to concatenate:
Code:
    ReplaceNulls = Table.ReplaceValue(SetDataTypes,null,each 
        Text.Combine(
            List.RemoveNulls(
                Record.ToList(
                    Record.SelectFields(_,{"First","Middle","Last"})
                )
            )
        , " "),Replacer.ReplaceValue,{"FullName"})
 
Upvote 0
Thanks a lot, Ron and billszysz for the solutions provided.

I have gone ahead with Ron's code since I was following his code.

Regards,
Harish S
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top