March 19, 2024

SamTech 365

PowerPlatform, Power Apps, Power Automate, PVA, SharePoint, C#, .Net, SQL, Azure News, Tips ….etc

Export Data from PowerApps to Excel (csv)

Today, we will look at how you can export data from your PowerApps applications 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 collection
  • 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.

PowerAutomate

This is most important component of the solution.

We will need an “Instant Cloud Flow”

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

 

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.

 

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

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

json(outputs('Content'))

 

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

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

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).

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).

 

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

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 (…)

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.

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:

Now, when you run your application and click 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 !

 

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