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
Davide_V
New Member

Import files with different extension type from the same folder

Hi,

I am new on this community so I hope this is the right place where to ask help for my issue. 
My power BI file was set to import .txt files from a folder, however the extension type of some of these files have been changed from .txt to .xlsx; so right now inside the folder there are both .txt and .xlsx files. When I update the Power BI file these .xlxs files are uploaded but completely "blank" (the information within these files is not loaded), so I would like to know if it is possible to import files with different extensions from the same folder or if I have to import them separately. 

Thanks in advance

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

You can modify your Power Query code to use different file ingestion routines (called functions) depending on the extension type of the file.  Note that .xlsx files have a totally different structure (and potentially many tabs that you need to choose from) than plain .txt files.

 

Something like this

 

let
Source = SharePoint.Files("https://xxx.sharepoint.com/teams/yyy", [ApiVersion = 15]),
#"Filtered Rows" = Table.SelectRows(Source, each ([Extension] = ".txt" or [Extension] = ".xlsx")),
#"Get File Contents" = Table.AddColumn(#"Filtered Rows", "File", each if [Extension]=".txt" then GetTXT([Content]) else GetXLSX([Content]))

in 

#"Get File Contents"

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Davide_V , Import a excel file separately.  Go go data transformation/ Edit Query mode. Right-click on the table and open the Advance editor.

Take this code.

Do the same with the text file.

Now compare the code and move the changes in excel source code text source code.

Take care of Path , column name and Type

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
lbendlin
Super User
Super User

You can modify your Power Query code to use different file ingestion routines (called functions) depending on the extension type of the file.  Note that .xlsx files have a totally different structure (and potentially many tabs that you need to choose from) than plain .txt files.

 

Something like this

 

let
Source = SharePoint.Files("https://xxx.sharepoint.com/teams/yyy", [ApiVersion = 15]),
#"Filtered Rows" = Table.SelectRows(Source, each ([Extension] = ".txt" or [Extension] = ".xlsx")),
#"Get File Contents" = Table.AddColumn(#"Filtered Rows", "File", each if [Extension]=".txt" then GetTXT([Content]) else GetXLSX([Content]))

in 

#"Get File Contents"

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

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.