In this article, I will provide information on how to export data from a collection in Power Apps to a CSV file using Power Automate.
Below are the components used in this document.
- Power Apps
- Power Automate
Introduction
Today we will export data from a Collection in Power Apps to a CSV file using a Power Automate. In my example I have few rows of data along with header which has to be exported to a csv file on click of a button in Power Apps. Below is the step by step way to put the data in the collection along with the header in Power Apps form and then use the Power Automate to export that collection to csv file.
Open Power Apps and create a new Form.
NOTE
In case you already have a Power Apps form created, you can ignore this step.
Step 1
Browse to
here and provide your Office 365 account details to login
Step 2
The below page will open and you can select either a template to start your form or you can select a blank app. (Make sure you select the right layout as well based on the target you want to build this app for.) For my example I am selecting Blank app with Tablet layout highlighted with yellow color in the below image.
Step 3
Empty form will be opened.
Create a collection in Power Apps along with the Headers
Step 1
I have a button and a few rows of data already present in my Power Apps form. You can get the data from any other source like SharePoint or SQL table based on your requirements.
Step 2
“OnSelect” property of the button, we would create a collection with the header and rows.
Here in the below example,
Header Names: “Source”, “Target”, “Projected Migration Time” and “Actual Migration Time”.
Collection name: “collcsvData”.
Collection with already existing rows of data: “colNumberedActualMigTime”
- ClearCollect(collcsvData, {Source: "Source", Target: "Target", PMT: "Projected Migration Time", AMT: "Actual Migration Time"},ForAll(colNumberedActualMigTime, {Source: AMTSiteName.Text, Target: AMTargetSiteName.Text, PMT: lblProjectedUnits.Text, AMT: txtAMT.Text}));
Step 3
Now we will add the entire Collection to a variable (comma separated, as we need to create a csv file), so that the variable can be passed to Power Automate. In the same “OnSelect” property, add the below line.
Here in the example,
Collection name: “collcsvData”
Variable Name: “varData”
- Set(varData, Concat (collcsvData, Source &","&Target&","&PMT&","&AMT &Char(10)));
Step 4
Now we will send this variable to Power Automate to create the csv file. In the same “OnSelect” property, call the Power Automate and send the variable as an input parameter.
Here in the example,
Power Automate Name: “MGR_GenerateCsvByBatchSql”
Variable Name: “varData”
- MGR_GenerateCsvByBatchSql.Run(varData);
Step 5
Now in Power Automate, we need to add a step as “Create file” as below. Use the input parameter coming from the Power Apps as “File Content”. Hence the file would be created in a SharePoint Document Library.
Step 6
Now we can add “Download” function to download the csv file. So in the same “OnSelect” property of the button in Power Apps, we can add below line.
Here in the example,
SharePoint Site Name: “MigrationManager”
SharePoint Document Library: “INV_DataToSql”
Csv File Name : sampleCSV
- Download("site/:x:/r/ teams/MigrationManager/ INV_DataToSql/sampleCSV.csv??d=w4cbeaf2098ed4620bcdf94ab549b504e&csf=1&e=AaU7I6");
Step 7
Test the functionality using preview (F5), click on the button. CSV file will be downloaded with the rows data present on the Power Apps.
That is it. I hope you have learned something new from this article and will utilize this in your work.