cancel
Showing results for 
Search instead for 
Did you mean: 
darogael

Export to CSV from Power Apps

Introduction:

The blog walks you through how you can export items from a gallery into a CSV using Power Automate with a OneDrive for Business connection.

 

Requirements:

  1. A Power App with a data connection to provide data for a gallery
  2. A Power Automate flow which data connection to OneDrive for Business

 

Step 1: Create and send the data from Power App.

Have an app created with a gallery that contains the data you need. You can even provide the option to filter the gallery based on the item selected from the drop down control.

 

We then collect all the items from the gallery in a temporary collection called ExportCSVCol. Then data from this collection is appended to a Set variable, to make sure the data is saved row-by-row we use the Char(10) at the end.

Finally the external variable is set to OneDrive to make the conversion to CSV using flow. Here is a screenshot of the formula:

 

Capture1.JPG

Step 2: Convert the data from Power App into a CSV file.

We now create a three step flow in Power Automate to receive the data from our app and convert it into a CSV file using OneDrive for Business. The converted CSV file is stored in OneDrive.

Important: It is important to note that this is a temporary file that must remain in OneDrive for Business and SHOULD NOT BE DELETED. You will be referencing this file in your app to download the CSV. This CSV file is auto-updated.

 

Here is a screenshot of the flow

Capture2.JPG

Step 3: Download the CSV file

In your Power App go back to the button you built in Step2 and add the remaining formula at the end. Notice the &Download=1 at the end? That is what forces the CSV file to download. The HTTP URL is what you get from OneDrive, the video walks you through the steps.

picture4.png

Here is a screenshot of the entire formula for the button

Capture3.JPG

Video:

This video walks you through the entire process step-by-step.

 

Conclusion:

Following the steps provided you can successfully export items from the gallery as a CSV file. By default the gallery will hold only 500 items. You can increase that to 2000 by changing the Data row limit in Advance Settings or you can add more filters to the gallery to only get the data you desire.

Comments

You can also create a Share link and return it to you App, which will get around the limitation of having to pre-create the file and not delete it.

 

Rodimus07_0-1599967626349.png

 

Anonymous
 
 
 
 

 

  We have used this guideline to export data from canvas app to CSV file under One drive for business. Now we are suffering by one issue when other users are calling the flow from canvas app than creator of One drive connection. So file is updated by the new content without any issue if user who created the One Drive connection is calling the flow, but when other users call it, file creating action under flow running history shows new content but .CSV file is not refreshed.  Is there any solution to make it possible for other users to call the flow so that file content would be refreshed under service account's One drive? 

Hi @Anonymous , I had the same issue.

The problem is that in this demo @darogael is using Collect instead of ClearCollect.

The ClearCollect function always Clear the Collection first and then Add the new content. The Collect, only add new contents.

But you can't use ClearCollect function with ForAll.

 

What I did was, I eliminated the second line that is  something like. It might be a little different depending on your data.

ForAll(BrowseGallery1.AllItems,Collect(ExportCSVCol,{user_id:UpnGal.Text,vehicle_name:VehicleNameGal.Text,request_status:StatusGal}));

 

And replaced it with a ClearCollect of the filtered gallery only:

ClearCollect(ExportCSVCol,BrowseGallery1.AllItems);

Anonymous

Hi @darogael 

Can you please help with me the import function?

I have export data to csv function but i am struggling to do import function whereby import excel file and will be updated in sharepoint list and gallery in my powerapp.

aaaa3_1-1675087825518.png

 

aaaa3_0-1675087696250.png

 

Export Data Code

 

Set(
varExportCSV,
""
);
ForAll(
gallery_inventory_4.AllItems,
Collect(
colExportCSV,
{
DeviceName: inventoryLabel_title.Text,
Memory: inventoryLabel_memory.Text,
Storage: inventoryLabel_storage.Text,
SerialNumber: inventoryLabel_serialNumber.Text,
CurrentUser: inventoryLabel_currentUser.Text,
Location: inventoryLabel_location.Text,
LoanStart: inventoryLabel_dateIssued.Text,
LoanEnd: inventoryLabel_dateEnd.Text,
LoanStatus: inventoryLabel_loanStatus.Text,
PreviousUser: inventoryLabel_previousUser.Text
}
)
);
Set(
varExportCSV,
"Serial Number, Device Name, Memory, Storage, Current User, Previous User, Location, Loan Status, Loan Start, Loan End" & Char(10) & Concat(
colExportCSV,
SerialNumber & "," & DeviceName & "," & Memory & "," & Storage & "," & CurrentUser & "," & PreviousUser & "," & Location & "," & LoanStatus & "," & LoanStart & "," & LoanEnd & Char(10)
)
);
ExportCSV.Run(
"CSVFile",
varExportCSV
);
Set(
varSuccess,
ExportCSV.Run(
"CSVFile",
varExportCSV
).completed
);
Clear(colExportCSV);
If(
varSuccess = "true",
Notify(
"CSV file created. Check your OneDrive to view the file.",
Success
)
);