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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Dividing huge csv into...
Power Automate
Answered

Dividing huge csv into smaller files

(0) ShareShare
ReportReport
Posted on by 12

Hello,

 

I have a problem with huge CSV file, which I am trying to convert to Excel spreadsheet. The problem is that the script works only for CSV files below 10,000 rows. My input CSV file has approximately 85,000 rows and it is different every day. Can you please let me know how to divide the CSV file in Power Automate into smaller files which I can then convert to Excel? And then what is the possibility to merge small spreadsheets into one 85,000 rows spreadsheet? The script that I am using:

function main(workbook: ExcelScript.Workbook, lineCSV: string[]) {
 let selectedSheet = workbook.getActiveWorksheet();
 const alllines = lineCSV;
 let counter = 1;
 for (let line of alllines) {
 if (line.includes(",")) {
 let items = line.split(",");
 selectedSheet.getRange("A" + counter+":G"+counter).setValues([[items[0], items[1], items[2], items[3], items[4], items[5], items[6]]]);
 counter++;
 }
 } 
 workbook.addTable(selectedSheet.getRange("A1:G" + counter), true).setName("ContactInfo");
}

 

Thank you

Agnes

 

Categories:
I have the same question (0)
  • Verified answer
    Chriddle Profile Picture
    8,513 Super User 2025 Season 2 on at

    Overview:

    Chriddle_2-1676393812854.png

     

     

    DataCSV: Compose action with original CSV

    RowCount: Compose Action with max row number (her 2 for test purposes)

    Lines: Compose action that splits the CSV at line break - dependent on your original CSV file, the line break might also be decodeUriComponent('%0D%0A')

     

     

    split(outputs('DataCSV'), decodeUriComponent('%0A'))

     

     

    Header: First row of those lines (the header of the CSV)

     

     

    first(outputs('Lines'))

     

     

    Initialize variable dataLines: Other rows (the data)

     

     

    skip(outputs('Lines'), 1)

     

     

    Do until: Loop until dataLines is empty

     

     

    length(variables('dataLines'))

     

     

    Csv: The new short CSV. You migth create a file with this after this action.

     

     

    @{outputs('Header')}
    @{join(
    	take(
    		variables('dataLines'),
    		min(
    			createArray(
    				outputs('RowCount'),
    				length(variables('dataLines'))
    			)
    		)
    	),
    	decodeUriComponent('%0A')
    )}

     

     

     NewDateLines: The unused dateLines

     

     

    skip(variables('dataLines'), outputs('RowCount'))

     

     

    Set variable dateLines: Set dateLines to NewDateLines

     

     

    @{outputs('NewDateLines')}

     

     

     

     

  • blueberrybush Profile Picture
    12 on at

    Thank you for this idea but unfortunately, it is not working for my csv for now.

    I am getting the data as attachment to the email, so I had to use Apply to each even when I have only one attachment.

    Here is the run:

    blueberrybush_0-1676469042828.png

    blueberrybush_2-1676469080725.png

    The DataCSV makes the following output:

    blueberrybush_3-1676470354028.png

    The raw output is:  "Work Email Address,ManagerEmailAlias\r\nv...

    v is the beginning of the new line, so I have on the end of every row \r\n in the output of this function

     

    and then the input to the Lines compose action is like this:

    blueberrybush_4-1676470453059.png

    Could you please tell me how to construct the DataCSV so it will work in next steps? It seems like it is making an array, which is not working for Csv action in "Do until" section.

  • Chriddle Profile Picture
    8,513 Super User 2025 Season 2 on at

    Please insert a Compose action before the failed Csv with following expression

    createArray(
    	outputs('RowCount'),
    	length(variables('dataLines'))
    )

    and share the output.

  • blueberrybush Profile Picture
    12 on at

    The output is:

    blueberrybush_0-1676547662856.png

     

    Can you please let me know what should I put in brackets of decodeUriComponent to make it work? I have tried both options provided by you and the result is the same.

    split(outputs('DataCSV'),decodeUriComponent('%0A'))

     

  • Chriddle Profile Picture
    8,513 Super User 2025 Season 2 on at

    Don't use my flow within another loop!

    Only use "Apply to each" to get the content of the attachment.

    Use function first(array) to get the first item of an array.

  • blueberrybush Profile Picture
    12 on at

    I have modified the flow:

    blueberrybush_0-1676553512728.png

    But unfortunately, I have an error in the Lines compose action:

    blueberrybush_1-1676553574700.png

     

  • Chriddle Profile Picture
    8,513 Super User 2025 Season 2 on at

    DataCSV is still in your "Apply to each" loop.

    Therefore it's an array, not the expected string.

    Rename this action to AttachmentCSVs

    And add a new Compose action with name DataCSV the following expression

     

    first('AttachmentCSVs')

     

     

  • BrunoBougleux Profile Picture
    4 on at

    I had another kind of error.... when setting a new value to dataLine variable, the P.A. raises a error about I'm trying to catch a string and put in an Array. But it's not true! 

    Sem título.png

    my newLine code: Array(skip(variables('dataLines'), outputs('QtdLinhas')))

    I already uses without the "array" function

  • BrunoBougleux Profile Picture
    4 on at

    I Solved Initializing a new Variable calling "Newline" with array type. then seting it in the ending.. 

    Sem título.png

     

     

     

    Now, How can I create the result files? 

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
trice602 Profile Picture

trice602 398 Super User 2025 Season 2

#2
David_MA Profile Picture

David_MA 323 Super User 2025 Season 2

#3
Expiscornovus Profile Picture

Expiscornovus 183 Most Valuable Professional

Last 30 days Overall leaderboard