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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
danextian
Super User
Super User

Combine text from all available columns into one in Power Query

Hi All,

 

I've been trying to solve this on my own with no luck.

 

I have a table with many columns. Some colums have nulll values, some don't. I want to remove all rows with just null values in all columns. Column is nulll, column 2 is null, column 3 is null so on and so forth... so if the concatenation of all these columns result to null, the row will be removed. 

 

I wan to do the concatenation without having combine the columns one by one using ampersands or Text.Combne and Text.From

Would be great if this is possible.










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


Proud to be a Super User!









"Tell me and I’ll forget; show me and I may remember; involve me and I’ll understand."
Need Power BI consultation, get in touch with me on LinkedIn or hire me on UpWork.
Learn with me on YouTube @DAXJutsu or follow my page on Facebook @DAXJutsuPBI.
2 ACCEPTED SOLUTIONS

You can just remove blank rows:

 

Remove blank rows.png

 

Resulting code:

let
    Source = Table.FromColumns({{1,null,3},{null,null,null}},type table[Number1 = number, Number2 = number]),
    #"Removed Blank Rows" = Table.SelectRows(Source, each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null})))
in
    #"Removed Blank Rows"

This checks both on nulls and "". If you only want to check for nulls, then you can adjust the code accordingly.

 

Specializing in Power Query Formula Language (M)

View solution in original post

v-huizhn-msft
Employee
Employee

Hi @danextian,

I reproduce using my simple table.

1.PNG

You can create a custom column using the formula.

2.PNG
Then remove the rows based on the custom column. Please see my Query statement below.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRQ0lEysQASQFasDlDAFMgGIkswDyRuZAwkLSCSRhCFOkrmMGkQAjFNwEqBhJlSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", Int64.Type}, {"Column3", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if(([Column1]=null)and([Column2]=null)and([Column3]=null)) then null else 1),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each [Custom] <> null and [Custom] <> "")
in
    #"Filtered Rows"


I will get the expected result.

4.PNG

Best Regards,
Angelia

 

View solution in original post

3 REPLIES 3
v-huizhn-msft
Employee
Employee

Hi @danextian,

I reproduce using my simple table.

1.PNG

You can create a custom column using the formula.

2.PNG
Then remove the rows based on the custom column. Please see my Query statement below.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjRQ0lEysQASQFasDlDAFMgGIkswDyRuZAwkLSCSRhCFOkrmMGkQAjFNwEqBhJlSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", Int64.Type}, {"Column2", Int64.Type}, {"Column3", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if(([Column1]=null)and([Column2]=null)and([Column3]=null)) then null else 1),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each [Custom] <> null and [Custom] <> "")
in
    #"Filtered Rows"


I will get the expected result.

4.PNG

Best Regards,
Angelia

 

vanessafvg
Super User
Super User

@danextian never tried it myself but @MarcelBeug has given me a formula before with list in power query maybe that can help?

 

https://msdn.microsoft.com/en-us/library/mt296612.aspx





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




You can just remove blank rows:

 

Remove blank rows.png

 

Resulting code:

let
    Source = Table.FromColumns({{1,null,3},{null,null,null}},type table[Number1 = number, Number2 = number]),
    #"Removed Blank Rows" = Table.SelectRows(Source, each not List.IsEmpty(List.RemoveMatchingItems(Record.FieldValues(_), {"", null})))
in
    #"Removed Blank Rows"

This checks both on nulls and "". If you only want to check for nulls, then you can adjust the code accordingly.

 

Specializing in Power Query Formula Language (M)

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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