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 Automate / Power Automate flow fo...
Power Automate
Suggested Answer

Power Automate flow for Transpose rows into column in Excel sheet

(1) ShareShare
ReportReport
Posted on by
Hi Community members,
I want to transpose and paste excel rows from one spreadsheet into another spreadsheet. There are only two rows in the spreadsheet. I was able to do this with the help of Power Automate flow and Power BI. I want this to be done by only Power Automate flow. Please help.
I have attached the Source file and expected destination file for your reference.
Thanks!
Categories:
I have the same question (0)
  • Suggested answer
    Haque Profile Picture
    3,653 on at
    Hi @MK-20061705-0,
     
    Thanks for posting in the forum. It seems like you didnt' post the desitnation file. The requirement you have - is easy to achieve using Power Automate only. Here are the steps you can follow:
     
     
    Pre-requisites:
    • Both Excel files should be stored in OneDrive for Business or SharePoint Online.
    • The source Excel data must be formatted as a Table (not just a range).
    • The destination Excel file should also have a Table where you want to paste the transposed data.
     

    [A] Trigger: Use a manual trigger or a scheduled trigger depending on when you want the flow to run.

    [B] Get rows from source Excel: Let's use the "List rows present in a table" action to get the rows from the source Excel table (Source File.xlsx).

    [C] Initialize a variable to build transposed data: Create an array variable to store the transposed rows.

    [D] Transpose the rows: Since Power Automate doesn’t have a direct transpose function, you can:

    This effectively converts rows into columns.

    • Loop through the columns of the source table.
    • For each column, create a new row in the array variable where each item corresponds to the values from that column across all rows.

    [E] Add rows to destination Excel: At this stage we can leverage "Add a row into a table" action inside a loop to insert each transposed row into the destination Excel table.

     

    Note: If your source has only two rows, the transpose will convert those rows into two columns in the destination.

     

    I am sure some clues I tried to give. If these clues help to resolve the issue brought you by here, please don't forget to check the box Does this answer your question? At the same time, I am pretty sure you have liked the response!
     
  • Chriddle Profile Picture
    8,708 Super User 2026 Season 1 on at
    If the row count is always 2, try this:
     
    first(outputs('Compose'))[item()]
    last(outputs('Compose'))[item()]
     
  • Suggested answer
    McPowerPlatform Profile Picture
    52 on at
    Hi @ , I believe I have what you need.
      
    Step 1: Test an Office Script
    1. In your sample Excel workbook, you have a worksheet named src that contains a table named Source.
    2. To test the Office Script, first save the Excel file to OneDrive or SharePoint. Then:
      • Open the workbook in Excel.
      • Select the Automate tab.
      • Click New Script and choose Create in Code Editor.
      • A sample script will appear in the editor on the right side of the screen. Replace it with the following code:
      
    function main(workbook: ExcelScript.Workbook) {
      // Get the active worksheet
      const sourceSheet = workbook.getActiveWorksheet();
     
      // Get the used range and its values
      const usedRange = sourceSheet.getUsedRange();
      const sourceValues = usedRange.getValues();
     
      // Transpose the data
      const transposedValues = sourceValues[0].map((_, colIndex) =>
        sourceValues.map(row => row[colIndex])
      );
     
      // Create or get the destination worksheet
      let destinationSheet = workbook.getWorksheet("Transposed");
      if (!destinationSheet) {
        destinationSheet = workbook.addWorksheet("Transposed");
      }
     
      // Define the starting cell
      const destinationStartCell = destinationSheet.getRange("A1");
     
      // Calculate the destination range size
      const rowCount = transposedValues.length;
      const columnCount = transposedValues[0].length;
     
      // Resize the destination range
      const destinationRange = destinationStartCell.getResizedRange(
        rowCount - 1,
        columnCount - 1
      );
     
      // Write the transposed values to the destination worksheet
      destinationRange.setValues(transposedValues);
    }
     
     
    • Save the script by clicking the pencil icon, entering a meaningful name, and selecting Save.

        
      Note: Office Scripts are stored in your OneDrive. The default location is typically the Office Scripts folder.
    • To test the script, click Run.

    • The script will:

      • Read the data from the active worksheet.
      • Create a new worksheet named Transposed (if it does not already exist).
      • Transpose the source data (swap rows and columns).
      • Write the transposed data starting at cell A1 on the Transposed worksheet.

      After the script completes, you should see the transposed version of your source data on the Transposed sheet.

     
    Step 2: Create a Power Automate Flow to Run the Office Script
    After testing and saving the Office Script, the next step is to create a Power Automate flow that runs the script automatically.
    Scenario
    In this example, the flow will:
    Trigger manually.
    Open the Excel workbook stored in OneDrive or SharePoint.
    Run the Office Script.
    Create or update the Transposed worksheet with the transposed data.

    Create the Flow
    1. Open Power Automate
    Navigate to https://make.powerautomate.com.
    Sign in with your Microsoft 365 account.
    Select Create from the left navigation menu.

    2. Create an Instant Cloud Flow
    Select Instant Cloud Flow.
    Enter a name, for example:
    Transpose Excel Data
    Choose the trigger:
    Manually trigger a flow
    Click Create.
    3. Add the “Run Script” Action
    Click + New Step.
    Search for Excel Online (Business).
    Select the action:
    Run script

    4. Configure the Excel Workbook
    Populate the required fields:
    Location: OneDrive for Business or SharePoint Site
    Document Library: Documents (if using SharePoint)
    File: Select the Excel workbook containing the Office Script
    Script: Select the script you saved earlier
    Example:
    Location: OneDrive for Business
    File: SourceFile.xlsx
    Script: Select the Script you've created and tested e.g. Transpose Source Data

    5. Save the Flow
    Click Save in the upper-right corner.
    Wait for the flow to be successfully saved.

    6. Test the Flow
    Click Test.
    Select Manually.
    Click Run Flow.
    Select Done.
    Power Automate will:
    Open the workbook.
    Execute the Office Script.
    Create the Transposed worksheet if it does not exist.
    Write the transposed data into the worksheet.
      See the attached image as the reference of the expected outcome
     
    Let me know if this works for you
    transp.png

    Your file is currently under scan for potential threats. Please wait while we review it for any viruses or malicious content.

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 377

#2
11manish Profile Picture

11manish 279

#3
David_MA Profile Picture

David_MA 234 Super User 2026 Season 1

Last 30 days Overall leaderboard