web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Suggested answer

Export a collection data to CSV in the column order of the collection

(0) ShareShare
ReportReport
Posted on by 525
Hi there!
 
I have several galleries to export to CSV.
So, for example, I put a button with this code:
 
_________________________________________________________________________________________
ClearCollect(colDataTempDestination , SortByColumns(Inventory_Destinations,"cr815_name"));
 
ForAll(colDataTempDestination, Collect(ColDataExport,
{
Destination:ThisRecord.Name,
Code: ThisRecord.Code,
Address: ThisRecord.Address,
City:  ThisRecord.City,
State: ThisRecord.State,
ZIP:  ThisRecord.ZipCode,
Country:  ThisRecord.Country.Name,
Status_Active: ThisRecord.Active
}));
 
Set(varJSONData, JSON(ColDataExport));
Set(VarLinkToFile, ExportDataToCSV.Run(varJSONData,"Destinations_" & Now() & ".csv").linktocsvfile);
 
Launch(VarLinkToFile);
 
Clear(ColDataExport)
_________________________________________________________________________________________
 
So, the code creates the collection and send this data to a Flow that receives the data, create a CSV Table and save it in OneDrive as CSV file.
 
 
Yes, I choosed Automatic for Columns... So the CSV file created, sorts the columns names in alphabetical order, instead the order I made in the collection:
 
Destination
Code
Address
City
State
ZIP
Country
Status_Active
 
And I want to use the same flow for all the exportations.
 
Is there any way to achive that? Or I need to create a flow for each gallery and format the columns in each of them?
 
Thanks for any help!
I have the same question (0)
  • Suggested answer
    WarrenBelz Profile Picture
    149,319 Most Valuable Professional on at
    Export a collection data to CSV in the column order of the collection
    If you want to put CSV columns in your desired order, you need to go back to the pre-JSON process as below
    With(
       {
          _Data:
          SortByColumns(
             Inventory_Destinations,
             "cr815_name"
          )
       },
       With(
          {
             _Export: 
             "Destination,Code,Address,City,State,ZIP,Country,Status_Active" & Char(10) & 
             Concat(
                _Data,
                Name & "," & Code & "," & Address & "," & City & "," & State & "," & ZipCode & "," & Country.Name & "," & Active
             )
          },
          Launch(
             ExportDataToCSV.Run(
                _Export,
                "Destinations_" & Now() & ".csv"
          ).linktocsvfile
       )
    );
    You also need to remove the JSON element from the Flow and simply create the file with the valid CSV now sent from Power Apps.
     
    This structure also eliminates a number of "one use" Collections and Variables "hanging around" in your app.
     
    Please ✅ Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like♥.
    Visit my blog Practical Power Apps    LinkedIn    Buy me a coffee
  • EmilioRoqueta69 Profile Picture
    525 on at
    Export a collection data to CSV in the column order of the collection
    I realized that the collection shows the columns in alphabetical order...

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Telen Wang – Community Spotlight

We are honored to recognize Telen Wang as our August 2025 Community…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 637 Most Valuable Professional

#2
stampcoin Profile Picture

stampcoin 570 Super User 2025 Season 2

#3
Power Apps 1919 Profile Picture

Power Apps 1919 473