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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
Anonymous
Not applicable

Delete multiple columns with condition - Power Query

Dear Community !

 

My data has columns names as the first day of each month (ex: 1/1/2019, 2/1/2019, 3/1/2019 etc) - 12 Columns for an year.

Need your help to figure out how to remove columns whose names DO NOT CONTAIN current year (2023 in this case), however, I don't want to hardcode the year. Currently I am using below, which solves the purpose, by using multiple lines for each year, however, I was looking for one PQ function.

 

Any help is welcome ! Thanks in advance !

= Table.RemoveColumns(#"Changed Type1",List.FindText(Table.ColumnNames(#"Changed Type1"),"2019"))

1 ACCEPTED SOLUTION
Adamboer
Responsive Resident
Responsive Resident

To remove the columns that do not contain the current year dynamically, you can use the following Power Query function: = Table.SelectColumns(#"Changed Type1", List.Select(Table.ColumnNames(#"Changed Type1"), each Text.Contains(_, Text.From(Date.Year(DateTime.LocalNow())), Comparer.OrdinalIgnoreCase))) This formula uses the Text.Contains function to check whether the column name contains the current year dynamically by using the Date.Year and DateTime.LocalNow functions. It then selects only the columns whose names contain the current year using the List.Select function, and returns the filtered table using the Table.SelectColumns function. This should help you achieve your goal of removing columns dynamically without hardcoding the year. Let me know if you have any further questions.

View solution in original post

2 REPLIES 2
Adamboer
Responsive Resident
Responsive Resident

To remove the columns that do not contain the current year dynamically, you can use the following Power Query function: = Table.SelectColumns(#"Changed Type1", List.Select(Table.ColumnNames(#"Changed Type1"), each Text.Contains(_, Text.From(Date.Year(DateTime.LocalNow())), Comparer.OrdinalIgnoreCase))) This formula uses the Text.Contains function to check whether the column name contains the current year dynamically by using the Date.Year and DateTime.LocalNow functions. It then selects only the columns whose names contain the current year using the List.Select function, and returns the filtered table using the Table.SelectColumns function. This should help you achieve your goal of removing columns dynamically without hardcoding the year. Let me know if you have any further questions.
Anonymous
Not applicable

THANK YOU @Adamboer ! Did the job precisely 🙂

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.