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
anshpalash
Helper II
Helper II

Keep all rows that contain 'x'

Hi,

 

I have a table of format:

nullxy
nullnullz
xnullnull
nullnullx
zzy


I want to keep only those rows which contain 'x'. The Pseudocode which I have in mind is:

If each row contains 'x', keep it else remove from table.

 

Output format:

nullxy
xnullnull
nullnullx

 

Can somebody please advise how to achieve this? Thanks!

 

2 ACCEPTED SOLUTIONS
Fowmy
Super User
Super User

@anshpalash 

Select All the columns (CTRL + A) > Under Add Column Tab, Merge Column, Give a Delimiter and merge.
In the New Column (Merged), Filter Rows Contains X

Fowmy_0-1633964049642.png


Code: Paste on a blank Query and check the steps

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WyivNyVHSUaoA4kqlWB24AJSqAotVIATAFKa6CrBYFVgH2KRYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Col1 = _t, Col2 = _t, Col3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Col1", type text}, {"Col2", type text}, {"Col3", type text}}),
    #"Inserted Merged Column" = Table.AddColumn(#"Changed Type", "Merged", each Text.Combine({[Col1], [Col2], [Col3]}, "|"), type text),
    #"Filtered Rows" = Table.SelectRows(#"Inserted Merged Column", each Text.Contains([Merged], "x")),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Merged"})
in
    #"Removed Columns"

 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

ERD
Community Champion
Community Champion

@anshpalash ,

One of the ways is to check whether one of the columns contains "x" value via separate column and then by filtering this column. For example:

ERD_0-1633964439250.png

 

ERD_1-1633964456694.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WyivNyVHSgVFVSrE60UoVCAEwBRJDVVcBFqsC69BRqlSKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"null" = _t, x = _t, y = _t]),
    #"Demoted Headers" = Table.DemoteHeaders(Source),
    #"Added Custom" = Table.AddColumn(#"Demoted Headers", "Custom", each if [Column1] = "x" or [Column2] = "x" or [Column3] = "x" then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = 1))
in
    #"Filtered Rows"

 

If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

View solution in original post

4 REPLIES 4
ERD
Community Champion
Community Champion

@anshpalash ,

One of the ways is to check whether one of the columns contains "x" value via separate column and then by filtering this column. For example:

ERD_0-1633964439250.png

 

ERD_1-1633964456694.png

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WyivNyVHSgVFVSrE60UoVCAEwBRJDVVcBFqsC69BRqlSKjQUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"null" = _t, x = _t, y = _t]),
    #"Demoted Headers" = Table.DemoteHeaders(Source),
    #"Added Custom" = Table.AddColumn(#"Demoted Headers", "Custom", each if [Column1] = "x" or [Column2] = "x" or [Column3] = "x" then 1 else 0),
    #"Filtered Rows" = Table.SelectRows(#"Added Custom", each ([Custom] = 1))
in
    #"Filtered Rows"

 

If this post helps, then please consider Accept it as the solution ✔️to help the other members find it more quickly.

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. Appreciate your Kudos.

Check out my latest demo report in the data story gallery.

Stand with Ukraine!


Here are official ways you can support Ukraine financially (accounts with multiple currencies):
1) Support the Armed Forces of Ukraine: https://bank.gov.ua/ua/about/support-the-armed-forces
2) Come Back Alive foundation: https://www.comebackalive.in.ua/

Thank you!

Thank you! @ERD 

Fowmy
Super User
Super User

@anshpalash 

Select All the columns (CTRL + A) > Under Add Column Tab, Merge Column, Give a Delimiter and merge.
In the New Column (Merged), Filter Rows Contains X

Fowmy_0-1633964049642.png


Code: Paste on a blank Query and check the steps

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WyivNyVHSUaoA4kqlWB24AJSqAotVIATAFKa6CrBYFVgH2KRYAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Col1 = _t, Col2 = _t, Col3 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Col1", type text}, {"Col2", type text}, {"Col3", type text}}),
    #"Inserted Merged Column" = Table.AddColumn(#"Changed Type", "Merged", each Text.Combine({[Col1], [Col2], [Col3]}, "|"), type text),
    #"Filtered Rows" = Table.SelectRows(#"Inserted Merged Column", each Text.Contains([Merged], "x")),
    #"Removed Columns" = Table.RemoveColumns(#"Filtered Rows",{"Merged"})
in
    #"Removed Columns"

 

 

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Thank you! @Fowmy 

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.

Top Solution Authors