Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
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!
Solved! Go to Solution.
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:
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
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:
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
Nice clean solution that still works in 2019!
Thank you 🙂
Is there ever likely to be a more solid solution to this? Don't get me wrong I like your solution but its more of a workaround until a proper solution is put in place.
Is it likely we will see XML given more attention as its a common format I am hit with and the thought of trying to manage to import it into Power Bi especially when the XML reflects a schema of several tables is just plain hairy.
Maybe even just letting powebi hook up to an XML database and create the connection that way would be more optimal.
Hi
what if i need to import from a folder some xlsb files with the same structure but i what to import only one worksheet?
Many many thanks!
Hi Alex, could you share the pbix please?
Great, thank you! I got it to work now. Excellent.
Edit : Nevermind .. i got it working
Can you upload the pbix as example Alex? Thanks
Hi amien,
Below is a link to a zip folder containing the example XML files and a PBIX file. If you extract the folder to your C drive, everything should work without editing the path in the query.
Alex, thanks for your reply, it halped me a lot in understanding how BI works. however I have an additional challenge- i have to combine multiple XML files with the same name and schema but from different folders into one datase. I was thinking of creating separate wueries for each file, but the folders are getting added all the time...
any advise?
thanks so much!
I just tested this and it worked for me.
Cheers
The "from XML" and "from folder gives different output and I am not able to nest out the relevant data in "from folder"
From XML
let
Source = Xml.Tables(File.Contents("C:\337.xml")),
Table0 = Source{0}[Table],
Table1 = Table0{1}[Table],
#"Changed Type" = Table.TransformColumnTypes(Table1,{{"Id", Int64.Type}, {"LglSeqNb", Int64.Type}, {"CreDtTm", type datetime}})
in
#"Changed Type"
From Folder
Source = Folder.Files("W:\XML folder")
Is it possible to combine Source = Xml.Tables and Source = Folder.Files ?