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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

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
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.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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