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
sse
Regular Visitor

Import multiple XML files

Is it possible to use the import from folder for multiple XML files? I have manged to extract the data I need from a single XML file using "import from XML" but not with the files from folder. Thank you!

1 ACCEPTED SOLUTION
alex-potter
Advocate IV
Advocate IV

The way I usually do it is with 2 queries: a folder query to get the paths/names of the files, and a function query to parse them.  

 

Steps:

  1. Query the folder where your XML files are
  2. Add a column that combines the path and file name to make an absolute path to the XML file and call it [Path]
  3. Create an XML query to one of the XML files in the folder
  4. Open advanced editor and create a parameter by adding (path as text) => at the top
  5. Replace the path specified inside Folder.Files() to path
  6. Close the advanced editor and name the query "getXML"
  7. In the Folder Query, add a custom column and call the getXML function by stating getXML([Path])
  8. Close and Load

    XML Parse Function Query
let
    Source = Folder.Files("C:\XML Files"),
    #"Removed Other Columns" = Table.SelectColumns(Source,{"Name", "Folder Path"}),
    #"Added Custom" = Table.AddColumn(#"Removed Other Columns", "Path", each [Folder Path] & [Name]),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "XML Data", each getXML([Path])),
    #"Expanded XML Data" = Table.ExpandTableColumn(#"Added Custom1", "XML Data", {"TITLE", "ARTIST", "COUNTRY", "COMPANY", "PRICE", "YEAR"}, {"TITLE", "ARTIST", "COUNTRY", "COMPANY", "PRICE", "YEAR"})
in
    #"Expanded XML Data"

Folder Query

(path as text) =>
let
    Source = Xml.Tables(File.Contents(path)),
    Table0 = Source{0}[Table],
    #"Changed Type" = Table.TransformColumnTypes(Table0,{{"TITLE", type text}, {"ARTIST", type text}, {"COUNTRY", type text}, {"COMPANY", type text}, {"PRICE", type number}, {"YEAR", Int64.Type}})
in
    #"Changed Type"

 

Message me if you would like an example PBIX file that does this

Alex

Alex Potter
Lead Visualization Engineer
Luxoft Inc.

View solution in original post

13 REPLIES 13

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.