Forum Discussion
Power Automate format
I'm utilizing Power Automate to export data into a CSV file. I would like to include a header and footer in the exported CSV file.
Current output
phone name address city state zip
234-456-5671 John Test address1 city1 state1 zip1
234-456-5672 Kevin Test address2 city2 state2 zip2
234-456-5673 Shane Test address3 city3 state3 zip3
234-456-5674 Ervin Text address4 city4 state4 zip4
Desired output:
10 SCADA.DB
4 STATUS phone name address city state zip
234-456-5671 John Test address1 city1 state1 zip1
234-456-5672 Kevin Test address2 city2 state2 zip2
234-456-5673 Shane Test address3 city3 state3 zip3
234-456-5674 Ervin Text address4 city4 state4 zip4
Hi jwb3d,
You cannot do this directly with the CSV export action since it does not support custom headers or footers. You need to build the file content manually as a string in Power Automate.Here is the full step by step approach:Step 1: Get your data
Use "List rows present in a table" (Excel) or "List rows" (Dataverse/SharePoint) to retrieve your records. Store the output, you will reference it in the Select action.
Step 2: Initialize your header variables
Add two "Initialize variable" actions before your loop.
Variable 1, name it
HeaderLine1, type Text, value10 SCADA.DBVariable 2, name it
HeaderLine2, type Text, value:4 STATUS phone name address city state zipStep 3: Build each data row using Select
Add a "Select" action. Set the From field to your list rows output. In the Map section, add a single key and use this expression as the value:
concat(item()?['phone'], ' ', item()?['name'], ' ', item()?['address'], ' ', item()?['city'], ' ', item()?['state'], ' ', item()?['zip'])This converts each row into a single space-delimited string.
Step 4: Join all rows into one string
Add a "Join" action. Set the From field to the Select output. Set the Join with field to this expression:
decodeUriComponent('%0A')This inserts a new line between each row.
Step 5: Assemble the full file content
Add an "Initialize variable" action, name it
FileContent, type Text. Set the value using this expression:concat(variables('HeaderLine1'), decodeUriComponent('%0A'), variables('HeaderLine2'), decodeUriComponent('%0A'), body('Join'))This stacks your two header lines on top of the data rows with proper line breaks.
Step 6: Write the file
Use "Create file" in SharePoint or OneDrive. Set the file name to something like
export.csv. Set the file content tovariables('FileContent').If you need a footer row at the bottom, add another static variable after the Join step and append it at the end of the concat expression in Step 5.
One thing to watch: if your data contains spaces within field values like a full address, consider switching the delimiter to a comma and wrapping each field in quotes inside the concat expression. That keeps your CSV parser from misreading columns.
Thank you!
Proud to be a Super User!
🏷️ Need more help?
✅ Don’t forget to Accept as Solution if this guidance worked for you.
❤️Your Like motivates me to keep helpingHello jwb3d,
Yes, this is possible in Power Automate.
The Create CSV Table action only generates the CSV content—it doesn't support adding custom headers or footers directly.
A common approach is:
Use Create CSV Table to generate the CSV data.
Use a Compose action (or variables) to prepend your custom header and append your footer.
Use the output of the Compose action when creating the file.
For example:
10 SCADA.DB 4 STATUS phone,name,address,city,state,zip <Create CSV Table output> <Footer text>
You can concatenate them using an expression like:
concat( '10 SCADA.DB', '\n\n', '4 STATUS phone,name,address,city,state,zip', '\n', outputs('Create_CSV_table'), '\n', 'Footer text' )Then use the output of the Compose action in the Create File step instead of the raw CSV output.
Best regards,
Omkar Shinde
Microsoft Fabric Enthusiast | Power BI Consultant
💡 If you found this response helpful, please consider giving it a Kudos.
✅ If this resolves your question, please mark it as the Accepted Solution to help others in the community.
2 Replies
- MJParikhSuper User
Hi jwb3d,
You cannot do this directly with the CSV export action since it does not support custom headers or footers. You need to build the file content manually as a string in Power Automate.Here is the full step by step approach:Step 1: Get your data
Use "List rows present in a table" (Excel) or "List rows" (Dataverse/SharePoint) to retrieve your records. Store the output, you will reference it in the Select action.
Step 2: Initialize your header variables
Add two "Initialize variable" actions before your loop.
Variable 1, name it
HeaderLine1, type Text, value10 SCADA.DBVariable 2, name it
HeaderLine2, type Text, value:4 STATUS phone name address city state zipStep 3: Build each data row using Select
Add a "Select" action. Set the From field to your list rows output. In the Map section, add a single key and use this expression as the value:
concat(item()?['phone'], ' ', item()?['name'], ' ', item()?['address'], ' ', item()?['city'], ' ', item()?['state'], ' ', item()?['zip'])This converts each row into a single space-delimited string.
Step 4: Join all rows into one string
Add a "Join" action. Set the From field to the Select output. Set the Join with field to this expression:
decodeUriComponent('%0A')This inserts a new line between each row.
Step 5: Assemble the full file content
Add an "Initialize variable" action, name it
FileContent, type Text. Set the value using this expression:concat(variables('HeaderLine1'), decodeUriComponent('%0A'), variables('HeaderLine2'), decodeUriComponent('%0A'), body('Join'))This stacks your two header lines on top of the data rows with proper line breaks.
Step 6: Write the file
Use "Create file" in SharePoint or OneDrive. Set the file name to something like
export.csv. Set the file content tovariables('FileContent').If you need a footer row at the bottom, add another static variable after the Join step and append it at the end of the concat expression in Step 5.
One thing to watch: if your data contains spaces within field values like a full address, consider switching the delimiter to a comma and wrapping each field in quotes inside the concat expression. That keeps your CSV parser from misreading columns.
Thank you!
Proud to be a Super User!
🏷️ Need more help?
✅ Don’t forget to Accept as Solution if this guidance worked for you.
❤️Your Like motivates me to keep helping - Omkar_1712Solution Specialist
Hello jwb3d,
Yes, this is possible in Power Automate.
The Create CSV Table action only generates the CSV content—it doesn't support adding custom headers or footers directly.
A common approach is:
Use Create CSV Table to generate the CSV data.
Use a Compose action (or variables) to prepend your custom header and append your footer.
Use the output of the Compose action when creating the file.
For example:
10 SCADA.DB 4 STATUS phone,name,address,city,state,zip <Create CSV Table output> <Footer text>
You can concatenate them using an expression like:
concat( '10 SCADA.DB', '\n\n', '4 STATUS phone,name,address,city,state,zip', '\n', outputs('Create_CSV_table'), '\n', 'Footer text' )Then use the output of the Compose action in the Create File step instead of the raw CSV output.
Best regards,
Omkar Shinde
Microsoft Fabric Enthusiast | Power BI Consultant
💡 If you found this response helpful, please consider giving it a Kudos.
✅ If this resolves your question, please mark it as the Accepted Solution to help others in the community.