I feel like just about every commercial app out there has the concept of Export to CSV. Turns out people like to grab their data and open it up in Excel. 🤷 Who Knew.
So today, let's walk through how easy it is to add Export to CSV into your Power Apps. Basically, we select some table data, encode it in JSON, and then ship it off to Power Automate which has built in actions to make it super easy.
Once the data is in Power Automate you can create a file an then save the file off to SharePoint, OneDrive, send it via an email attachment or basically anything else you can dream of. That is the beauty of flow, once you have the CSV file you can do anything you want.
And speaking of Selecting items in a Gallery, we even cover how to Select All and Deselect All in the video version of this. Video: Power Apps Export to CSV with Power Automate
Pro Tip: This tutorial assumes you’ve already got your Power App setup and you’re just focusing on the exporting bit. We’re skipping the app creation part today and heading straight into the exciting stuff: generating a JSON, converting it into CSV, and getting it where it needs to go. Check out the video above if you want to see the app creation and item selection.
Creating the JSON from Power Apps
First things first, we need to get our data into a JSON format. Power Apps can output data in various forms, but for exporting, JSON is the golden ticket.
Step 1: Using the JSON Function
In Power Apps, the JSON() function is your new best friend. This function allows you to take any table of data (like the items in your app) and convert it into JSON format. That’s the format Power Automate loves to work with.
Here's how to create a JSON variable in Power Apps:
UpdateContext({varJSON: JSON(yourTable, JSONFormat.IndentFour)})
This will take your data and turn it into a JSON string, which we’ll use in the next step to create our CSV.
Now depending on your table, the previous step might be way more complicated. There JSON function doesn't work against controls or some advanced data types. In the video, we go through all of that but below you can see an example of just how complicated things can get.
That is intense, and why the video is a bit longer but that is a good insight of what this looks like in the real world.
Parsing JSON in Power Automate
Next, it’s time to head into Power Automate. This is where the magic of converting our JSON data into a CSV file happens.
Step 2: Parsing the JSON
Inside your Power Automate flow, the first step after receiving the JSON from Power Apps is to parse it. This basically tells Power Automate what data you’re working with and how it’s structured.
Add the Parse JSON action to your flow.
Under "Content," insert the JSON data coming from Power Apps.
Generate a schema by clicking "Generate from sample" and paste the sample JSON you want to parse.
Boom! 🎉 Now Power Automate understands what’s inside your JSON file, and you can start working with that data.
Converting JSON to CSV
Now that Power Automate knows what your data looks like, let’s convert it into CSV format.
Step 3: Create CSV Table Action
We’ll use the Create CSV Table action in Power Automate to handle this. Here’s how:
Add the Create CSV Table action.
Choose your parsed JSON output as the input for this action.
If you want to customize the columns, select Custom under "Columns" and specify the fields you want in your CSV (like Order Date, Total Amount, etc.).
This action will generate a perfectly formatted CSV file with all your data.
Now in the screenshot you can see some Expressions. Reminder, while you will bring over some raw data from Power Apps you can still fix it up. Order Date I updated to make a nicer looking format and Total Amount I set to look like currency. Once again, all of the gory details are covered in the video.
Sending Your CSV File via Email
With your CSV file ready to go, you can do just about anything with it. In this example, we’re going to email the file as an attachment.
Step 4: Sending the CSV as an Attachment
Add the Send an Email (V2) action to your flow. Then, use the following settings:
To: Your desired recipient (or just yourself to test it out!).
Subject: Something like, “Here’s your CSV export!”
Body: You can keep this simple for now, like “Check out the attached CSV file.”
Attachment Name: Export.csv (or whatever you want to call it).
Attachment Content: Use the output from the Create CSV Table action here.
Hit "Save," test it out, and if all goes well, you’ll receive an email with your brand-new CSV file attached.
Bonus: Embedding Data as HTML Table (Optional)
If you want to get even fancier, instead of attaching the CSV file, you can embed the data directly in your email as an HTML table.
To do this:
Add the Create HTML Table action (instead of CSV).
Use the same parsed JSON as the input.
In your Send an Email action, insert the HTML table output into the body of the email.
Now, instead of a file attachment, your recipients will see a nicely formatted table right in their inbox! 📬
Wrap Up
And that’s it! 🎉 You've just learned how to export data to CSV from Power Apps using Power Automate. With this knowledge, you can take your data anywhere it needs to go—whether that’s an inbox, cloud storage, or even SharePoint.
Exporting CSVs from Power Apps is a super practical feature, especially if you're working with large datasets or need to automate data sharing across different teams. So go ahead, give it a try, and make your life a whole lot easier!
If you need help with this or any apps or flows, just click the Contact button and we are happy to help. We have services that range from 30-minute screen shares to full scale project development.