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
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
Employee
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
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.