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 / Filter Pivots in excel...
Power Automate
Unanswered

Filter Pivots in excel worksheet using Desktop flow without Macro

(0) ShareShare
ReportReport
Posted on by 4

I need to filter Pivots in excel worksheet using Desktop flow. My organization policy does not allow me to use Macros and do not have an access to OneDrive or SharePoint to use office scripts. PAD does not have any actions related to Pivots, I tried using "Run VB Script" but its not allowing me to filter the pivot table. Any help would be appreciated.

I have the same question (0)
  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @VenkatB 

     

    Would it be possible for you to provide a screenshot of your Excel document to understand how it looks like? Additionally, could you explain the specific objectives you're aiming to achieve with the filters?

     

    I understand that you're attempting to apply filters, but I'd appreciate clarity on whether you're planning to apply them at the field level or if there are other considerations involved.

     

    This would help me better understand your requirements and provide more tailored assistance.

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀. If you'd like to appreciate me, please write a LinkedIn recommendation 🙏

  • kinuasa Profile Picture
    801 Most Valuable Professional on at

    While you can filter pivot tables using scripts like the one below, if VBScript is prohibited due to policy, it may not function.

     

    With GetObject("C:\Test\Excel\Book1.xlsx")
     With .Worksheets(1).PivotTables(1).PivotFields(1)
     .ClearAllFilters
     .CurrentPage = "(All)"
     End With
    End With
  • VenkatB Profile Picture
    4 on at

    Here is the screenshot of pivot table. Need to filter the column "Action", filter values would be dynamic(a list variable from PAD). Macros are not allowed but "Run VBScript" action is allowed. Any help with VBscript code would be highly appreciated.

    VenkatB_0-1711605106618.png

     

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

     

     

     

     

    @VenkatB 

    Please follow the suggested steps and utilize the provided PowerShell scripts:

     

    Ensure to set up the filename of your Excel sheet and the name of the pivot sheet, along with the field you intend to apply as a filter in the pivot table, as illustrated in the screenshot below.

    Deenuji_0-1711630622598.png

     

    Full code:

    SET ExcelFileName TO $'''\"C:\\Deenu\\test_excel.xlsx\"'''
    SET Pivot_Sheetname TO $'''\"Sheet2\"'''
    SET Filter_FieldName TO $'''\"Jawatan\"'''
    @@copilotGeneratedAction: 'False'
    Scripting.RunPowershellScript.RunPowershellScript Script: $'''# Load Excel application
    $excel = New-Object -ComObject Excel.Application
    $excel.Visible = $true # Set to $true if you want Excel to be visible
    
    # Open the workbook
    $workbook = $excel.Workbooks.Open(%ExcelFileName%)
    $worksheet = $workbook.Sheets.Item(%Pivot_Sheetname%)
    
    # Get the pivot table
    $pivotTable = $worksheet.PivotTables(1)
    
    
    # Add \"Nama\" as a row filter
    $pivotField = $pivotTable.PivotFields(%Filter_FieldName%)
    $pivotField.Orientation = [Microsoft.Office.Interop.Excel.XlPivotFieldOrientation]::xlRowField
    
    # Save and close the workbook
    $workbook.Save()
    $workbook.Close()
    
    # Quit Excel
    $excel.Quit()
    
    
    # Clean up COM objects
    [System.Runtime.Interopservices.Marshal]::ReleaseComObject($pivotTable) | Out-Null
    [System.Runtime.Interopservices.Marshal]::ReleaseComObject($worksheet) | Out-Null
    [System.Runtime.Interopservices.Marshal]::ReleaseComObject($workbook) | Out-Null
    [System.Runtime.Interopservices.Marshal]::ReleaseComObject($excel) | Out-Null
    Remove-Variable pivotTable, worksheet, workbook, excel''' ScriptOutput=> PowershellOutput

     

     

     

    How to copy/paste the above into you PAD?

    Deenuji_1-1711630666984.gif

     

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀. If you'd like to appreciate me, please write a LinkedIn recommendation 🙏

     

  • VenkatB Profile Picture
    4 on at

    Thanks for your code @Deenuji, this adds another pivot filed to the filter. But I am expecting to apply filters on "Action" data field as follows.

    VenkatB_1-1711711528035.png

    I would like to filter only 5 specific values from available data. These 5 values are coming from PAD list variable as an Array.

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

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 252 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 169

#3
Haque Profile Picture

Haque 154

Last 30 days Overall leaderboard