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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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.

 

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
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Top Solution Authors
Top Kudoed Authors