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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Dee
Helper III
Helper III

Store file name as column value on power query

I'm importing data from different sources, excel and csv, I'm looking for a way to add a column that specifies the name of the source file.

eg. DataSource 1 of type excel has the field animal name and the name of the file is Test 1.xlsx, DataSource 2 has the same format but of type csv.

 

Desired output.

 

Name  SourceName

Cat       Test1.xlsx

Dog      Test1.xlsx

Cat        Test.csv

 

I would like this to be updated on each import.

 

Any help on how to achieve this would be highly appreciated

4 REPLIES 4
PhilipTreacy
Super User
Super User

@Dee 

Ah. that wasn't mentioned in your initial question.



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


PhilipTreacy
Super User
Super User

HI @Dee 

If you use load the file(s) using Get Data -> From Folder, then filter for the file(s) you want, you'll end up with a column showing the filename, for example

 

let
    Source = Folder.Files("d:\temp"),
    #"Filtered Rows" = Table.SelectRows(Source, each ([Name] = "data.xlsx"))
in
    #"Filtered Rows"

 

 

Gives me this

QUERY-FILENAME.png

Regards

Phil


If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi @PhilipTreacy 

 

I am getting data from a web source.

 

Web API specifically on powerapps power query.

mahoneypat
Microsoft Employee
Microsoft Employee

This is possible.  You start with your table of filenames and folderpaths, then you can concatenate those into into a custom column, either using a function or an if then else that use Excel.Workbook or CSV.Document depending on file type.  It would be easier to have one query that gets all your CSVs (potentially two separate queries, one for each Folder), and another that gets all your Excel files (or two).  You can then make sure the column names match and append them all together.  You can then uncheck  Enable Load on all but the final appended table.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

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.