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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Create CSV file from P...
Power Apps
Answered

Create CSV file from Power Automate with column headers in different order

(0) ShareShare
ReportReport
Posted on by 28

Hello everyone. Long time i try to solve this issue, but cannot figure it out so far. Read a lot of posts here, internet, youtube... etc.

I have SP List and from that list I create collection CBCOLLECTFIN like drop some unused fields.

SPList:

Dimo_3-1671199341553.png

 

After creating some variables, executing CSVEXPORTFIN.Run power automate flow:

----------------

Set(varDroppedColumn,DropColumns(CBCOLLECTFIN,"Account","Author","AutoNumber","ComplianceAssetId","DDS","EGN","Editor","Invoice","Product","Invoice_Billing","{Path}","{FilenameWithExtension}","{FullPath}","{Identifier}","{IsFolder}","{Link}","{ModerationComment}","{Name}","{Thumbnail}","{TriggerWindowEndToken}","{VersionNumber}","{ModerationStatus}","{TriggerWindowStartToken}"));
Set(varFormattedJSON,JSON(varDroppedColumn,JSONFormat.IndentFour));
CSVEXPORTFIN.Run(varFormattedJSON)

----------------

Power automate flow CSVEXPORTFIN:

Dimo_0-1671197261025.png

 

 

Third step in the flow is Create CSV table:

Dimo_1-1671197361672.png

 

This flow is working, but the headers in CSV file is in alphabetical order. I want different order. Probably, I have to use CUSTOM columns, but I don't know how to approach VALUES dynamically. I know, that collection in powerapps has build-in behavior of alphabetical order creation, regardless SPList columns order.

 

Dimo_2-1671198971869.png

Can you help?

 

Categories:
  • Verified answer
    WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    Hi @Dimo ,

    If you want your columns in order, you need to go back to the "old school" way of sending a Text file using Concat

    UpdateContext(
     {
     varCSVFile,
     "Header1,Header2,Header3,Header4" & Char(10) &
     Concat(
     DataSource,
     Field1 & "," & Field2 & "," Field3 & "," Field1 & Char(10)
     )
     }
    )
    

    then it gets much easier in the Flow as the output is already a CSV file and you do not need any of the JSON or file creation stuff.

     

    Please click Accept as solution 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 Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • Dimo Profile Picture
    28 on at

    HI WarrenBelz,

    Thanks. I will try this.

  • dbp Profile Picture
    10 on at

    This likely happens because of empty cells in the first row of the (to be) csv.

     

    A scalable elegant solution is possible, I've answered it here for a similar PowerBI problem.

  • Verified answer
    rcallan Profile Picture
    25 on at

    Ideally the order of the columns should match the order of the inputted data. There is already an idea for reordering columns in the Microsoft Forum which needs a lot of votes to be considered. I have created a generic, Export to CSV function which I use across multiple apps so having the output of the csv to match the input data would make more sense.

     

    Here is the link to the idea or search for 'Reorder Capabilities for Create CSV Table' in the Community / Submit ideas and vote for it if you think it a good idea

     

    https://ideas.powerautomate.com/d365community/idea/286b433a-f43d-4fb9-8e64-5aacd7b01ec5

  • Dimo Profile Picture
    28 on at

    Hi rcallan,

    Thanks for the answer and suggestion. I will take a look. 🙂

     

    Regards,

    Dimo

  • Hack-7 Profile Picture
    226 Moderator on at

    @WarrenBelz how would you do this if working with a gallery?

     

    Currently, I am doing a

    ForAll(

      galleryName.AllItems,

        Collect(

        collectNameToExport,

          {

            ID: ThisRecord.ID, Blah: ThisRecord.someInfo

          }

        )

    )

  • WarrenBelz Profile Picture
    156,528 Most Valuable Professional on at

    @Hack-7 ,

    The same format as I posted except the Data Source would be the Gallery.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 395 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 260 Most Valuable Professional

Last 30 days Overall leaderboard