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
Anonymous
Not applicable

connecting to xpf files

I am trying to automate a connection to a folder of .xpf files that contain daily updates from a machine.  The files can be opened in word or excel, it's really just text output, but I'd like to avoid this step and just pull them directly into Power BI.  I can work with a solution in R or Python if there are any.  Thanks! 

1 ACCEPTED SOLUTION

@Anonymous Here is my Transform Sample File query

let
    Source = Xml.Tables(Parameter1),
    #"Expanded TEXT" = Table.ExpandTableColumn(Source, "TEXT", {"s", "n"}, {"TEXT.s", "TEXT.n"}),
    #"Expanded TEXT.s" = Table.ExpandTableColumn(#"Expanded TEXT", "TEXT.s", {"Element:Text", "Attribute:HEADLINE", "Attribute:META", "Attribute:VAL", "Attribute:UNDERLINE"}, {"TEXT.s.Element:Text", "TEXT.s.Attribute:HEADLINE", "TEXT.s.Attribute:META", "TEXT.s.Attribute:VAL", "TEXT.s.Attribute:UNDERLINE"})
in
    #"Expanded TEXT.s"

 

This is the main query:

let
    Source = Folder.Files("c:\temp\xpf"),
    #"Filtered Hidden Files1" = Table.SelectRows(Source, each [Attributes]?[Hidden]? <> true),
    #"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File", each #"Transform File"([Content])),
    #"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
    #"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File"}),
    #"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File", Table.ColumnNames(#"Transform File"(#"Sample File")))
in
    #"Expanded Table Column1"

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

11 REPLIES 11
Anonymous
Not applicable

@Greg_Deckler 

I did try to do that, replacing the code that is automatically generated with the code you provided, but with "Source= Folder.Files" instead of "Source=Xml.tables" but I get the following error....

janet-carpenter_0-1621958037902.png

 

I really appreciate your help with this!

@Anonymous Here is my Transform Sample File query

let
    Source = Xml.Tables(Parameter1),
    #"Expanded TEXT" = Table.ExpandTableColumn(Source, "TEXT", {"s", "n"}, {"TEXT.s", "TEXT.n"}),
    #"Expanded TEXT.s" = Table.ExpandTableColumn(#"Expanded TEXT", "TEXT.s", {"Element:Text", "Attribute:HEADLINE", "Attribute:META", "Attribute:VAL", "Attribute:UNDERLINE"}, {"TEXT.s.Element:Text", "TEXT.s.Attribute:HEADLINE", "TEXT.s.Attribute:META", "TEXT.s.Attribute:VAL", "TEXT.s.Attribute:UNDERLINE"})
in
    #"Expanded TEXT.s"

 

This is the main query:

let
    Source = Folder.Files("c:\temp\xpf"),
    #"Filtered Hidden Files1" = Table.SelectRows(Source, each [Attributes]?[Hidden]? <> true),
    #"Invoke Custom Function1" = Table.AddColumn(#"Filtered Hidden Files1", "Transform File", each #"Transform File"([Content])),
    #"Renamed Columns1" = Table.RenameColumns(#"Invoke Custom Function1", {"Name", "Source.Name"}),
    #"Removed Other Columns1" = Table.SelectColumns(#"Renamed Columns1", {"Source.Name", "Transform File"}),
    #"Expanded Table Column1" = Table.ExpandTableColumn(#"Removed Other Columns1", "Transform File", Table.ColumnNames(#"Transform File"(#"Sample File")))
in
    #"Expanded Table Column1"

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

Thanks Greg!  That worked!

Anonymous
Not applicable

@Greg_Deckler That works to connect to a single file.  Do you know how I would modify that to connect to a folder where daily reports will be added?

@Anonymous Use a Folder query. It will auto-recognize the file as XML, at least it did in my case. So you point the query to the folder and then choose Combine and Transform. It will come up with one of the files, a sample file and you again want to Transform. A bunch of queries get created and you want to edit the Transform Sample File query. You perform the transformations there and then those get repeated for every file in the folder and they all get appended together.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler thanks!  I'll see if I can make that work!

Anonymous
Not applicable

@Greg_Deckler 

 

When I open in notepad, I get a lot of extra stuff, so it's clearly not clean text output, needs to be unpacked somehow.  I've tried to use the text and excel file connections, but those don't work.  

 

Here's one of the files: https://drive.google.com/file/d/1-MCbPxHOYpLSgk8EHWM4JoR_b-UH-67X/view?usp=sharing 

 

janet-carpenter_0-1621873959773.png

 

@Anonymous OK, that is an XML file. You can use the XML file connector. I was able to do that successfully. XML is a bit of a pain to work with because you will have a bunch of expansions that you will need to do in order to get to the actual data.

 

Here is an example of expanding that file to get to some data:

let
    Source = Xml.Tables(File.Contents("C:\Users\gdeckler\Downloads\PRT1112_20357.XPF")),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Attribute:Version", Int64.Type}}),
    #"Expanded TEXT" = Table.ExpandTableColumn(#"Changed Type", "TEXT", {"s", "n"}, {"TEXT.s", "TEXT.n"}),
    #"Expanded TEXT.s" = Table.ExpandTableColumn(#"Expanded TEXT", "TEXT.s", {"Attribute:HEADLINE", "Attribute:META", "Attribute:VAL"}, {"TEXT.s.Attribute:HEADLINE", "TEXT.s.Attribute:META", "TEXT.s.Attribute:VAL"}),
    #"Expanded TEXT.n" = Table.ExpandTableColumn(#"Expanded TEXT.s", "TEXT.n", {"Attribute:META", "Attribute:VAL"}, {"TEXT.n.Attribute:META", "TEXT.n.Attribute:VAL"})
in
    #"Expanded TEXT.n"

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Anonymous
Not applicable

@Greg_Deckler looks like I can't upload a file, here is a view of part of one of the files as it looks in word.  let me know if there's another way to answer your question

 

janet-carpenter_0-1621873030404.png

 

@Anonymous So, can you open the file in Notepad? If it truly is a Text file, you should be able to use the Text/CSV connector or if it truly opens in Excel, maybe the Excel connector? Can you share a file on OneDrive or Box or something?


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

@Anonymous Can you post an example of the kind of xpf file you are using? In doing research, there are many different possibilities for the data stored in an XPF file.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.