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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
skiotterjeffa
New Member

Parsed Filename as Column when connecting to a folder containing multiple Excel files

I have a folder with several Excel files:

 

Earnings Report June 2018.xlsx

Earnings Report May 2018.xlsx

Earnings Report April 2018.xlsx

etc.

 

I need to combine them in in Power BI, but I want to retain the commission period month that is found in the filename and display that month as a calculated column in Power BI.

 

I have been able to calculate the commission period on the Source step in a calculated colum.

 

I have found many examples of how to do this with CSV files, but I don't have an option for getting a CSV file without opening in Excel and saving as a new file format, which we are trying to avoid.

 

What is tripping me up is how to drill down into the specific sheet I want in the Excel workbook. With the CSV file, the data is on the first 'Table' when you expand the Binary. In an Excel file, the first Table is a listing of the Sheets when you drill into the binary. Then you can drill into a second table and see the data.

 

With CSV, you can do a Table.AddColumn and loop through all Csv.Document, even including a filter for your column separator, etc.

 

If I am just dealing with one Excel file and navigate into a Sheet, this code is created:

= #"Imported Excel"{[Item="Earning Summary",Kind="Sheet"]}[Data]

 

I cannot figure out the syntax in Power BI to wrap that in an each loop, though.

 

Thank You

Jeff

4 REPLIES 4
v-yulgu-msft
Employee
Employee

Hi @skiotterjeffa,

 

You can add a custom column:

=Text.Range(Text.Range([Name],16),0,(Text.Length(Text.Range([Name],16))-10))

1.PNG

 

Best regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
TomMartens
Super User
Super User

Hey,

 

maybe the content of your folder looks something like this:

Import xlsx from a folder - 001.png

 

you can use the "Extensions" column to filter down to the xlsx files that you wand to process.

 

Then you can use the PowerQuery function "Excel.Content" to create a custom column like so:

Excel.Workbook([Content])

 

Import xlsx from a folder - 002.png

 

This returns a table object for each xlsx file.

 

image.png

 

If you expand the column you will see this

image.png

 

The Data column contains data from the workbook, all the other columns contain additional meta information about the content of "Data".

 

Hopefully this gets you started.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Tom, That method did retain the filename in a column, yes.

 

I'm unable to transform the data, however.  The data needs to have the first row of each Excel file promoted to a header. It will also have the first 14 rows removed.

 

I tried updating the formula for my new expanded column on data with

= Table.PromoteHeaders(Table.ExpandTableColumn(#"Added Custom", "Custom", {"Name", "Data"}, {"Custom.Name", "Custom.Data"}), [PromoteAllScalars=true]).

But that isn't showing the column names promoted in the preview.

 

I also tried doing the PromoteHeaders on the AddedColum step where the each loop was. When I did that, my expanded Custom.Data column no longer showed the table.

 

Thank you for your help.

Hi @skiotterjeffa,

 

"I'm unable to transform the data, however.  The data needs to have the first row of each Excel file promoted to a header. It will also have the first 14 rows removed."

 

Could you post some dample data to illustrate your scenario?

 

Regards,

Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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