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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Sofimerce1
New Member

Dynamically delete column names

Hello everyone, I am trying to dynamically delete column names. 

 

Background on my query: my source is linked to a sharepoint folder that contains multiple Excel sheets and I upload a new one everyday. The data I use for the Power BI is the most recent upload. So the source is the folder then I filter based on Upload date for the latest file, then expand the most recent upload to get the content. 

 

I tried creating a list of all the column names from the source and find text (as explained in this video) because my source is the sharepoint folder that includes all of the Excel files. So when I create the Column name list it shows me the attributes of the folder "File Name, Date Modified, Date Uploaded, etc)- not the column names within those files. 

 

I am trying to delete headers that contain the word "Budget". There are hundreds of columns and every file has a different location of Budget columns. 

 

Any way of helping? @parry2k @amitchandak @Greg_Deckler or anyone else! 🙂

6 REPLIES 6
christinepayton
Super User
Super User

If you were to "unpivot other columns" with the first column selected, you'd be able to filter out "Budget" pretty easily in the UI just as a column-level filter. 

parry2k
Super User
Super User

@Sofimerce1 you can paste the following code and there is one step I added which will remove the budget columns dynamically.

 

 

let
    Source = Excel.Workbook(File.Contents("C:\Users\parvi\Downloads\Week 4 - sample file.xlsx"), null, true),
    Sheet1_Sheet = Source{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Promoted Headers" = Table.PromoteHeaders(Sheet1_Sheet, [PromoteAllScalars=true]),
    #"Table Remove Budget Columns" = Table.SelectColumns(#"Promoted Headers", List.RemoveMatchingItems(Table.ColumnNames(#"Promoted Headers"), List.Select(Table.ColumnNames(#"Promoted Headers"), each Text.Contains(_, "Budget"))))
in 
#"Table Remove Budget Columns"

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@Sofimerce1 if you share a sample excel file (remove sensitive information) and what columns you want to remove or keep, provide the rules, will get you the solution.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

Thank you!!

 

Model 1: I want to remove those column that have Budget - starts in DX

Sofimerce1_0-1694456991929.png

 

Model 2: I want to remove those column that have Budget - starts in DW

Sofimerce1_1-1694457229343.png

 

Let me knw if this gives you clarity. Thank you!!!

Not an image of parts of a worksheet, the actual workbook, that can be uploaded to OneDrive, BOX or the like, and shared anonymously.   Please then reply with the sharing link.

 

How to Get Your Question Answered Quickly - Microsoft Fabric Community

Gotcha, thanks.

 

Here you will find the initial data set. And now here you will find an updated version that will replace the previous data set. As you can see two columns were added: One in the middle of the data set, and one at the end. I want to dynamically delete those columns that have "Budget" but I cannot delete the last x amount of columns because the Budget Columns shift continously. Also, I cannot make a List the Source Columns because the source is the folder. 

 

Let me know if this is more helpful. Thanks. 

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 community update carousel

Fabric Community Update - June 2025

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