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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
RahulPBI
Helper I
Helper I

Conditional Column to check If Column Blank or null then append or use non blank column

Hi Expert 

I have three columns some of the columns have data, some have blanks and some are null

What I am trying to do is create a conditional column in power query which will check column1, column2 & column3 and merge the data into another column

It needs to ignore the blanks and null values and if two columns have data it merges both the data with a space in between

 

See below screen shots of the data and the expected result. I have a sample pbix file but not sure how to upload it here

 

Thanks

 

 

Annotation 2020-05-27 220615.pngAnnotation 2020-05-27 221020.png

1 ACCEPTED SOLUTION

@RahulPBI ,

 

Try this m code:

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bZDJCsMgEIbfJeccGpfYHs2maEuL0UMJeYOQW9+/IyodpDjgzPfPxmxbQy+i46xpm2h7mwGvQC9qcIPoyQg8cKQchnFMIhediOL5OY5Skf38rdOyLtN/wTmFBbBgrTUm0URm72atEdDq8Q4lloQyRkvTDDVlvO8raCGT3CuIN/pNUGpWymMwLd7jHbwxIRhTiI+9KUMnE9d4lQCLUI4H5IEvyM75+xc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Ref1 = _t, Ref2 = _t, Ref3 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Ref1", type text}, {"Ref2", type text}, {"Ref3", type text}}),
#"Replaced Value" = Table.ReplaceValue(#"Changed Type","",null,Replacer.ReplaceValue,{"Ref1", "Ref2", "Ref3"}),
#"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","null",null,Replacer.ReplaceValue,{"Ref1", "Ref2", "Ref3"}),
#"Added Custom" = Table.AddColumn(#"Replaced Value1", "Custom", each let
_1 = if [Ref1] <> null then [Ref1] else "",
_2 = if [Ref2] <> null then [Ref2] else "",
_3 = if [Ref3] <> null then [Ref3] else "" in
_1 & " " & _2 & " " & _3),
#"Trimmed Text" = Table.TransformColumns(#"Added Custom",{{"Custom", Text.Trim, type text}})
in
#"Trimmed Text"

 



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

Proud to be a Super User!



View solution in original post

4 REPLIES 4
camargos88
Community Champion
Community Champion

Hi @RahulPBI ,

 

You can use GoogleDrive/OneDrive/Dropbox to upload it.

 



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

Proud to be a Super User!



Thanks Ricardo

Hope the below helps

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bZDJCsMgEIbfJeccGpfYHs2maEuL0UMJeYOQW9+/IyodpDjgzPfPxmxbQy+i46xpm2h7mwGvQC9qcIPoyQg8cKQchnFMIhediOL5OY5Skf38rdOyLtN/wTmFBbBgrTUm0URm72atEdDq8Q4lloQyRkvTDDVlvO8raCGT3CuIN/pNUGpWymMwLd7jHbwxIRhTiI+9KUMnE9d4lQCLUI4H5IEvyM75+xc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Ref1 = _t, Ref2 = _t, Ref3 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Ref1", type text}, {"Ref2", type text}, {"Ref3", type text}})
in
#"Changed Type"

 

Regards

 

 

 

@RahulPBI ,

 

Try this m code:

 

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bZDJCsMgEIbfJeccGpfYHs2maEuL0UMJeYOQW9+/IyodpDjgzPfPxmxbQy+i46xpm2h7mwGvQC9qcIPoyQg8cKQchnFMIhediOL5OY5Skf38rdOyLtN/wTmFBbBgrTUm0URm72atEdDq8Q4lloQyRkvTDDVlvO8raCGT3CuIN/pNUGpWymMwLd7jHbwxIRhTiI+9KUMnE9d4lQCLUI4H5IEvyM75+xc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Ref1 = _t, Ref2 = _t, Ref3 = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Ref1", type text}, {"Ref2", type text}, {"Ref3", type text}}),
#"Replaced Value" = Table.ReplaceValue(#"Changed Type","",null,Replacer.ReplaceValue,{"Ref1", "Ref2", "Ref3"}),
#"Replaced Value1" = Table.ReplaceValue(#"Replaced Value","null",null,Replacer.ReplaceValue,{"Ref1", "Ref2", "Ref3"}),
#"Added Custom" = Table.AddColumn(#"Replaced Value1", "Custom", each let
_1 = if [Ref1] <> null then [Ref1] else "",
_2 = if [Ref2] <> null then [Ref2] else "",
_3 = if [Ref3] <> null then [Ref3] else "" in
_1 & " " & _2 & " " & _3),
#"Trimmed Text" = Table.TransformColumns(#"Added Custom",{{"Custom", Text.Trim, type text}})
in
#"Trimmed Text"

 



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

Proud to be a Super User!



@camargos88 

 

Perfect

 

Thank you, very much appreciated

 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

Top Solution Authors