SamTech 365

Power Platform, Copilot & SharePoint guides by Samir Daoudi

Export Data from PowerApps to Excel (csv)

Export data from a Power Apps canvas app to Excel as a CSV file with Power Automate, step by step, including formatting the output.
PowerApps to Excel2 – Export Data from PowerApps to Excel (csv)

Today, we will look at how you can export data from your PowerApps to Excel.

Basically, the scenario of today’s post, is to dump a collection from PowerApps to a .csv file.

Requirements:

We need the following:

PowerApps Canvas Application

This can also be a model-driven app, you will need to create a simple app (or have your existing app) with the following:

  • A Gallery to display your data
  • The Export Button, which will call the Power Automate and pass the collection to be exported.

Here is an example of my basic application:

  • 1st, I am initialising a collection on the App.OnStart event, you might be using your existing collectionExport Data from PowerApps to Excel (csv)
  • Next, I will put a gallery in my PowerApps Screen – This Step is optional, just to show me the data before I export it.
  • Last, we need an Export Button, which will be used to call our Power Automate later. We will come back to the Button’s action after we create the Power Automate.

Export Data from PowerApps to Excel (csv) – screenshot 2PowerAutomate

This is most important component of the solution.

We will need an “Instant Cloud Flow”

Export Data from PowerApps to Excel (csv) – screenshot 3

Please, make sure to use “PowerApps” Trigger for the new flow, provide a name and let’s get started !

Export Data from PowerApps to Excel (csv) – screenshot 4

 

Add a new action, “Compose“, please rename the action to something user friendly, and for the value, chose, “Ask in PowerApps“, this will create an input parameter for your Power Automate.

Export Data from PowerApps to Excel (csv) – screenshot 5

 

Next, you will need to parse the content, using the JSON function.
We will be passing our collection from PowerApps in a JSON format, so we will need to de-serialise the input to get the structured data.

You can add the action “Create a CSV Table”

Export Data from PowerApps to Excel (csv) – screenshot 6

For the from value of this action, use the expression:

json(outputs('Content'))

Export Data from PowerApps to Excel (csv) – screenshot 7

 

Now, we need to create a new file with the output of the “Create CSV table”,

To do so, we will use OneDrive for Business to create the new file.

Add the action “Create file”

Export Data from PowerApps to Excel (csv) – screenshot 8

Provide the file’s location, name and content. The content should be the output of “Create a CSV Table” action:

Export Data from PowerApps to Excel (csv) – screenshot 9

Now, we can create a share link to return from PowerAutomate to PowerApps, the link will be used to open or download the newly create file (the export file).

Export Data from PowerApps to Excel (csv) – screenshot 10

This action takes couple of parameters,

  • ID of the file (this needs to be the ID from the previous action “Create file“),
  • Type of link, this can be edit or view link.
  • Last, the scope of your link, anonymous (public) or organisation (internal link).

Export Data from PowerApps to Excel (csv) – screenshot 11

 

Finally, we will return the link to PowerApps, to do so, we will need to use the “Respond to PowerApps” action.

Export Data from PowerApps to Excel (csv) – screenshot 12

I have added an output of type Text, and used the Web Url from the previous action as value of the output parameter.

Now, back to PowerApps, we will need to attach our PowerAutmate to the PowerApps Application.

To do so,

1- Click the PowerAutomates tab.

2- Select the Add Flow button.

3- Add your new flow, if you can’t see it yet, try to refresh the list (…)

Export Data from PowerApps to Excel (csv) – screenshot 13

All good, now we can call the PowerAutomate from our Button.

To do so, select your Export Button and use the following action in the OnSelect Event.

Export Data from PowerApps to Excel (csv) – screenshot 14

This would have been enough to trigger the flow, but, as we are expecting an output value from the flow, I will assign the result of the flow call to a variable, which I can use later to navigate to the newly created file as follow:

Export Data from PowerApps to Excel (csv) – screenshot 15

Now, when you run your application and click PowerApps to Excel on the Export Button, the call will be made and after couple of seconds the link to your new file will open in a new tab, and Voila !

Export Data from PowerApps to Excel (csv) – screenshot 16

 

Full code (PowerApps and PowerAutomate) available from Github –> https://github.com/samirlogisam/PowerApps-Export-To-Excel

Related guides

Discover more from SamTech 365

Subscribe now to keep reading and get access to the full archive.

Continue reading