Forum Discussion

Davide_V's avatar
Davide_V
New Member
6 years ago
Solved

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...
  • lbendlin's avatar
    6 years ago

    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"