cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
cnr
Advocate II
Advocate II

Adding headings to a CSV file in PowerApps

Hi all,

 

My code below works fine when exporting to a CSV. I just need to figure out how to add headings to the columns, would anyone know how ?

ForAll(
    Gallery4_4.AllItems,
    Collect(
        ExportCSVCol,
        {
            TradeNumber: Label34_9.Text,
            FundName: Label35_17.Text,
            TD: Label36_7.Text,
            CCY: Label38_7.Text,
            MarketPrice: Label39_7.Text,
            AMT: Label37_14.Text,
            RevisedAmt: Label37_15.Text,
            Borrowers: Label33_7.Text,
            CounterParties: Label40_7.Text,
            TradeStatus: Label41_9.Text,
            Comments1: Label41_10.Text
        }
    )
);
Set(
    ExportCSVVar,
    Concat(
        ExportCSVCol,
        TradeNumber & "," & FundName & "," & TD & "," & CCY & "," & MarketPrice & "," & AMT & "," & RevisedAmt & "," & Borrowers & "," & CounterParties & "," & TradeStatus & Char(10)
    )
);
Set(
    SuccessVar,
    ExportCSVDemo.Run(
        "CSVTradesFile",
        ExportCSVVar
    ).completed
);
If(
    SuccessVar = "true",
    Launch("https://ofiz-my.sharepoint.com/:x:/g/personal/kiansean_lee_vistra_com/ER5_4KCLBfBFh8qyZo9nv-wB0ou4dCFf01WbvAVivLLO_Q?e=xNyPac&Download=1")
)

 

Thanks,

Conor

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User
Super User

@cnr 

Please consider changing your Formula to the following:

With({_ExportCSVVar:
    "TradeNumber,FundName,TD,CCY,MarketPrice,AMT,RevisedAmt,Borrowers,CounterParties,TradeStatus" & Char(10) &
        Concat(Gallery4_4.AllItems, 
               Label34_9.Text & "," & Label35_17.Text & "," & Label36_7.Text & "," & Label38_7.Text & "," & 
               Label39_7.Text & "," & Label37_14.Text & "," & Label37_15.Text & "," & Label33_7.Text & "," & 
               Label40_7.Text & "," & Label41_9.Text & Char(10)
        )
    },

        Set(SuccessVar, ExportCSVDemo.Run("CSVTradesFile", _ExportCSVVar).completed)
);

If(
    SuccessVar = "true",
    Launch("https://ofiz-my.sharepoint.com/:x:/g/personal/kiansean_lee_vistra_com/ER5_4KCLBfBFh8qyZo9nv-wB0ou4dCFf01WbvAVivLLO_Q?e=xNyPac&Download=1")
)

There really is no need for a collection to do any of this, so the above does everything in context.

 

This will add a header to the text being sent to the flow, then followed by the rows from the gallery.

 

I hope this is helpful for you.

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

5 REPLIES 5
RandyHayes
Super User
Super User

@cnr 

Please consider changing your Formula to the following:

With({_ExportCSVVar:
    "TradeNumber,FundName,TD,CCY,MarketPrice,AMT,RevisedAmt,Borrowers,CounterParties,TradeStatus" & Char(10) &
        Concat(Gallery4_4.AllItems, 
               Label34_9.Text & "," & Label35_17.Text & "," & Label36_7.Text & "," & Label38_7.Text & "," & 
               Label39_7.Text & "," & Label37_14.Text & "," & Label37_15.Text & "," & Label33_7.Text & "," & 
               Label40_7.Text & "," & Label41_9.Text & Char(10)
        )
    },

        Set(SuccessVar, ExportCSVDemo.Run("CSVTradesFile", _ExportCSVVar).completed)
);

If(
    SuccessVar = "true",
    Launch("https://ofiz-my.sharepoint.com/:x:/g/personal/kiansean_lee_vistra_com/ER5_4KCLBfBFh8qyZo9nv-wB0ou4dCFf01WbvAVivLLO_Q?e=xNyPac&Download=1")
)

There really is no need for a collection to do any of this, so the above does everything in context.

 

This will add a header to the text being sent to the flow, then followed by the rows from the gallery.

 

I hope this is helpful for you.

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Hi @RandyHayes 

Thanks for coming back to me. It is downloading in CSV but not with the headers you've put in, below what the output on the last run. Could I need a refresh somewhere or is it possible its showing me an old CSV?

 

cnr_0-1634141543676.png

 

RandyHayes
Super User
Super User

@cnr 

Your issue is going to be in how you create that file in the flow you are calling.  You app is now sending the correct data including the header.  So when it gets to your flow, somehow that you are creating the excel file is excluding the header.

I would look at any previous run of the flow and see what is happening at each step and where the header is being removed/ignored.

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Ah yes I see it in there now. Thanks a mill for your help! 

RandyHayes
Super User
Super User

@cnr 

Happy to help!

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
NOTE: My normal response times will be Mon to Fri from 1 PM to 10 PM UTC (and lots of other times too!)
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
Super User 2 - 2022 Congratulations 768x460.png

Welcome Super Users

The Super User program for 2022 - Season 2 has kicked off!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

<
Users online (2,315)