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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
ValeriaBreve
Post Patron
Post Patron

Remove columns based on whether they contain a string

Hello,

I would like to remove columns from my query if they contain a certain string.

Ex. below. If I wanted to remove all columns in the query containing the string "p", then Column3 would be removed:

 

Column1Column2Column3
eeg
fdh
gcu
hai
bqj
dbn
shp

 

Is this possible?

Thanks!

Kind regards

Valeria

1 ACCEPTED SOLUTION
alannavarro
Resolver I
Resolver I

Hello, I tried to do it but I did a lot of steps, I think there must be something more easy...

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlXSAeN0pVidaKU0ICsFiDPAvHQgKxmIS8G8DCArEYgzwbwkIKsQiLPAPJAekEgemFcMNkFHqUApNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
Custom1 = Table.ToColumns(Source),
Custom2 = List.Transform(Custom1,each List.Contains(_,"p")),
#"Converted to Table" = Table.FromList(Custom2, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
Custom3 = Table.ColumnNames(Source),
#"Converted to Table1" = Table.FromList(Custom3, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Added Index1" = Table.AddIndexColumn(#"Converted to Table1", "Index", 0, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index1", "Custom", each #"Converted to Table"[Column1]{[Index]}),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each if [Custom] = false then [Column1] else null),
#"Filtered Rows" = Table.SelectRows(#"Added Custom1", each ([Custom.1] <> null)),
#"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows",{"Custom.1"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Other Columns",{{"Custom.1", "Custom"}}),
Custom4 = Source,
#"Removed Other Columns1" = Table.SelectColumns(Custom4,#"Renamed Columns"[Custom])
in
#"Removed Other Columns1"

View solution in original post

4 REPLIES 4
AnkitKukreja
Super User
Super User

Hi! @ValeriaBreve 

 

As far as I know, that's not possible. But you can use the option to remove the column directly to remove that unwanted column.

 

For Power BI trainings or support dm or reach out to me on LinkedIn.
If my response has successfully addressed your question or concern, I kindly request that you mark this post as resolved. Additionally, if you found my assistance helpful, a thumbs-up would be greatly appreciated.

Thanks,
Ankit Kukreja
www.linkedin.com/in/ankit-kukreja1904

Hello, the solution from @alannavarro works nicely 🙂

alannavarro
Resolver I
Resolver I

Hello, I tried to do it but I did a lot of steps, I think there must be something more easy...

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSlXSAeN0pVidaKU0ICsFiDPAvHQgKxmIS8G8DCArEYgzwbwkIKsQiLPAPJAekEgemFcMNkFHqUApNhYA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t, Column3 = _t]),
Custom1 = Table.ToColumns(Source),
Custom2 = List.Transform(Custom1,each List.Contains(_,"p")),
#"Converted to Table" = Table.FromList(Custom2, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
Custom3 = Table.ColumnNames(Source),
#"Converted to Table1" = Table.FromList(Custom3, Splitter.SplitByNothing(), null, null, ExtraValues.Error),
#"Added Index1" = Table.AddIndexColumn(#"Converted to Table1", "Index", 0, 1, Int64.Type),
#"Added Custom" = Table.AddColumn(#"Added Index1", "Custom", each #"Converted to Table"[Column1]{[Index]}),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each if [Custom] = false then [Column1] else null),
#"Filtered Rows" = Table.SelectRows(#"Added Custom1", each ([Custom.1] <> null)),
#"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows",{"Custom.1"}),
#"Renamed Columns" = Table.RenameColumns(#"Removed Other Columns",{{"Custom.1", "Custom"}}),
Custom4 = Source,
#"Removed Other Columns1" = Table.SelectColumns(Custom4,#"Renamed Columns"[Custom])
in
#"Removed Other Columns1"

Nice! If there is another way I will try it but for now yours work very well - thank you!

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.

Top Solution Authors