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 / How to create pivot ta...
Power Automate
Unanswered

How to create pivot table in excel using power automation

(0) ShareShare
ReportReport
Posted on by 159

How to create pivot table in excel using power automation

Categories:
  • Rhiassuring Profile Picture
    8,692 Moderator on at

    Is the table going to be the same every time?
    You could use Power Automate Desktop, and use mostly hot keys in Excel to do this. You will need to ensure you have premium licensing if it will be unattended. 

  • jiwhite Profile Picture
    500 on at

    Write an Office Script to create the Pivot table from the Automate menu, for example:

     

    function main(workbook: ExcelScript.Workbook) {
        let wsData = workbook.getWorksheet("Details");
        let tblDetails = wsData.getTable("Details");
        let wsPivot = workbook.getWorksheet("Sheet1");
        let rngPivot = wsPivot.getRange("A1:B10");
        wsPivot.addPivotTable("PivotTest",tblDetails,rngPivot);
    }
     
    Then, call the script in your flow using a Run Script connector.
  • neerajpokh Profile Picture
    159 on at

    Hi @jiwhite 

    can you please tell me all steps which need to follow.

    means like where to write Office Script

  • jiwhite Profile Picture
    500 on at

    In Excel 365 online, click on the Automate tab, then New Script to write Office Script code.  It's language is TypeScript, which is a strongly typed version of JavaScript. After writing the Office Script, create a flow that uses the Excel Online (Business) Run Script connector to run the Office Script.

    jiwhite_0-1660155641102.png

    In the Run script connector, you specify the workbook that is running the script and which script to run, for example:

    jiwhite_2-1660155836538.png

     

    You can pass additional text information to and from scripts by adding additional properties in the main function, then there will additional boxes to complete in the connector and you'll be able to use what is returned in following connectors, for example:

     

    function main(workbook: ExcelScript.Workbook, tablename:string):string[] {

       // function content using input variable, i.e., tablename string

       let values = workbook.getTable(tablename).getHeaderRowRange().getValues0 as string[][];

       // return value matching type of main return, i.e., string array of header row

       return values[0];

    }

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

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 425

#2
11manish Profile Picture

11manish 323 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 274

Last 30 days Overall leaderboard