cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
MarianneElver
Regular Visitor

xml or power bi dataset to csv

Hi,

 

I fetch an xml file from ftp to Onedrive for Business and then load it into Power BI through Power Automate flow.

 

It happens on a on a daily basis.

 

A colleague of mine is eager to get this data as a csv-file on another ftp-server.

 

I have searched in vain for xml/csv transformation possibilities that does not require heavy license cost of third party products.

 

Any suggestions?

 

Thanks!

😊Marianne

 

 

Sample of xml:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<inventory xmlns="http://www.demandware.com/xml/impex/inventory/2007-05-31">
<inventory-list>
<header list-id="inventory">
<default-instock>false</default-instock>
</header>
<records>
<record product-id="1000010-3168S-L">
<allocation>0</allocation>
<perpetual>false</perpetual>
</record>
<record product-id="1000010-3168S-M">
<allocation>0</allocation>
<perpetual>false</perpetual>
</record>
<record product-id="1000010-3168S-S">
<allocation>0</allocation>
<perpetual>false</perpetual>
</record>
<record product-id="1000010-3168S-XL">
<allocation>0</allocation>
<perpetual>false</perpetual>
</record>
<record product-id="1000010-7025S-XL">
<allocation>0</allocation>
<perpetual>false</perpetual>
</record>
<record product-id="1000010-7025S-XS">
<allocation>0</allocation>
<perpetual>false</perpetual>
</record>
<record product-id="1000010-7025S-XXL">
<allocation>0</allocation>
<perpetual>false</perpetual>
</record>
</records>
</inventory-list>
</inventory>

1 ACCEPTED SOLUTION

Accepted Solutions
Paulie78
Super User III
Super User III

You can do it like this:

2021-04-21_14-53-31.png

Output is:

1000010-3168S-L,0,false
1000010-3168S-M,0,false
1000010-3168S-S,0,false
1000010-3168S-XL,0,false
1000010-7025S-XL,0,false
1000010-7025S-XS,0,false
1000010-7025S-XXL,0,false

Expressions Used:

Select Action: From
json(xml(outputs('XML')))['inventory']['inventory-list']['records']['record']

Selection Action: Map
concat
(
  item()['@product-id'], ',',
  item()['allocation'], ',',
  item()['perpetual']
)

Compose action (Named CSV in Screenshot)
join(body('Select'),  decodeUriComponent('%0A'))

 

Alternatively, if you copy the below code, and go into your clipboard, you can paste the solution in:

{"id":"2a6a24d5-3a06-4d6b-9cae-a6b0-2105bf4a","brandColor":"#8C3900","connectionReferences":{},"connectorDisplayName":"Control","icon":"data&colon;image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=","isTrigger":false,"operationName":"Create_CSV_from_XML","operationDefinition":{"type":"Scope","actions":{"XML":{"type":"Compose","inputs":"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<inventory xmlns=\"http://www.demandware.com/xml/impex/inventory/2007-05-31\">\n<inventory-list>\n<header list-id=\"inventory\">\n<default-instock>false</default-instock>\n</header>\n<records>\n<record product-id=\"1000010-3168S-L\">\n<allocation>0</allocation>\n<perpetual>false</perpetual>\n</record>\n<record product-id=\"1000010-3168S-M\">\n<allocation>0</allocation>\n<perpetual>false</perpetual>\n</record>\n<record product-id=\"1000010-3168S-S\">\n<allocation>0</allocation>\n<perpetual>false</perpetual>\n</record>\n<record product-id=\"1000010-3168S-XL\">\n<allocation>0</allocation>\n<perpetual>false</perpetual>\n</record>\n<record product-id=\"1000010-7025S-XL\">\n<allocation>0</allocation>\n<perpetual>false</perpetual>\n</record>\n<record product-id=\"1000010-7025S-XS\">\n<allocation>0</allocation>\n<perpetual>false</perpetual>\n</record>\n<record product-id=\"1000010-7025S-XXL\">\n<allocation>0</allocation>\n<perpetual>false</perpetual>\n</record>\n</records>\n</inventory-list>\n</inventory>","runAfter":{}},"Select":{"type":"Select","inputs":{"from":"@json(xml(outputs('XML')))['inventory']['inventory-list']['records']['record']","select":"@concat\r\n(\r\n  item()['@product-id'], ',',\r\n  item()['allocation'], ',',\r\n  item()['perpetual']\r\n)"},"runAfter":{"XML":["Succeeded"]},"description":"json(xml(outputs('XML')))['inventory']['inventory-list']['records']['record']"},"CSV":{"type":"Compose","inputs":"@join(body('Select'),  decodeUriComponent('%0A'))","runAfter":{"Select":["Succeeded"]},"description":"join(body('Select'),  decodeUriComponent('%0A'))"}},"runAfter":{}}}

 

Like this example:

2021-04-16_12-02-32.gif

See how you get on.

View solution in original post

2 REPLIES 2
Paulie78
Super User III
Super User III

You can do it like this:

2021-04-21_14-53-31.png

Output is:

1000010-3168S-L,0,false
1000010-3168S-M,0,false
1000010-3168S-S,0,false
1000010-3168S-XL,0,false
1000010-7025S-XL,0,false
1000010-7025S-XS,0,false
1000010-7025S-XXL,0,false

Expressions Used:

Select Action: From
json(xml(outputs('XML')))['inventory']['inventory-list']['records']['record']

Selection Action: Map
concat
(
  item()['@product-id'], ',',
  item()['allocation'], ',',
  item()['perpetual']
)

Compose action (Named CSV in Screenshot)
join(body('Select'),  decodeUriComponent('%0A'))

 

Alternatively, if you copy the below code, and go into your clipboard, you can paste the solution in:

{"id":"2a6a24d5-3a06-4d6b-9cae-a6b0-2105bf4a","brandColor":"#8C3900","connectionReferences":{},"connectorDisplayName":"Control","icon":"data&colon;image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZlcnNpb249IjEuMSIgdmlld0JveD0iMCAwIDMyIDMyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPg0KIDxwYXRoIGQ9Im0wIDBoMzJ2MzJoLTMyeiIgZmlsbD0iIzhDMzkwMCIvPg0KIDxwYXRoIGQ9Im04IDEwaDE2djEyaC0xNnptMTUgMTF2LTEwaC0xNHYxMHptLTItOHY2aC0xMHYtNnptLTEgNXYtNGgtOHY0eiIgZmlsbD0iI2ZmZiIvPg0KPC9zdmc+DQo=","isTrigger":false,"operationName":"Create_CSV_from_XML","operationDefinition":{"type":"Scope","actions":{"XML":{"type":"Compose","inputs":"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<inventory xmlns=\"http://www.demandware.com/xml/impex/inventory/2007-05-31\">\n<inventory-list>\n<header list-id=\"inventory\">\n<default-instock>false</default-instock>\n</header>\n<records>\n<record product-id=\"1000010-3168S-L\">\n<allocation>0</allocation>\n<perpetual>false</perpetual>\n</record>\n<record product-id=\"1000010-3168S-M\">\n<allocation>0</allocation>\n<perpetual>false</perpetual>\n</record>\n<record product-id=\"1000010-3168S-S\">\n<allocation>0</allocation>\n<perpetual>false</perpetual>\n</record>\n<record product-id=\"1000010-3168S-XL\">\n<allocation>0</allocation>\n<perpetual>false</perpetual>\n</record>\n<record product-id=\"1000010-7025S-XL\">\n<allocation>0</allocation>\n<perpetual>false</perpetual>\n</record>\n<record product-id=\"1000010-7025S-XS\">\n<allocation>0</allocation>\n<perpetual>false</perpetual>\n</record>\n<record product-id=\"1000010-7025S-XXL\">\n<allocation>0</allocation>\n<perpetual>false</perpetual>\n</record>\n</records>\n</inventory-list>\n</inventory>","runAfter":{}},"Select":{"type":"Select","inputs":{"from":"@json(xml(outputs('XML')))['inventory']['inventory-list']['records']['record']","select":"@concat\r\n(\r\n  item()['@product-id'], ',',\r\n  item()['allocation'], ',',\r\n  item()['perpetual']\r\n)"},"runAfter":{"XML":["Succeeded"]},"description":"json(xml(outputs('XML')))['inventory']['inventory-list']['records']['record']"},"CSV":{"type":"Compose","inputs":"@join(body('Select'),  decodeUriComponent('%0A'))","runAfter":{"Select":["Succeeded"]},"description":"join(body('Select'),  decodeUriComponent('%0A'))"}},"runAfter":{}}}

 

Like this example:

2021-04-16_12-02-32.gif

See how you get on.

View solution in original post

Hi, thanks a lot, I succeeded following your input!
This was really helpful and I also learned a lot along the way, being a fairly newbie to automation.
Thanks again 🙂

Helpful resources

Announcements
Process Advisor

Introducing Process Advisor

Check out the new Process Advisor community forum board!

MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Top Solution Authors
Top Kudoed Authors
Users online (26,688)