Select multiple items in filter using filter pivot table activity

I need to select multiple items in a filter of Pivot table. Using Filter Pivot table activity inside a for each datatable loop only selects last item inputted. Is there a way to select multiple items?

@kartiki_sharma

Welcome to the community

If you need to select multiple then you need to give them all at once

In for loop it might not work…you might need to go with macro

Cheers

How can I give all values at once? In configure filter value, we need to pass a string. It doesn’t take array of string

@kartiki_sharma

If you have the values dynamically then go with macro

Sub FilterPivotTable(filterString)
    Dim ws As Worksheet
    Dim pt As PivotTable
    Dim pf As PivotField
    Dim filterValues As Variant
    Dim value As Variant
    Dim var As String

    ' Set worksheet and PivotTable
    Set ws = ThisWorkbook.Sheets("Sheet2") ' Change to your sheet name
    Set pt = ws.PivotTables("PivotTable1") ' Change to your PivotTable name

    ' Get the filter values
    ' Dim filterString As String
    ' filterString = "f,e" ' Change this to your comma-separated string
    filterValues = Split(filterString, ",")

    ' Set the PivotField to filter
    Set pf = pt.PivotFields("Col3") ' Change to your field name

    ' Clear existing filters
    pf.ClearAllFilters
    
    ' Show all items initially
    On Error Resume Next
    For Each Pi In pf.PivotItems
        var = Pi.value
        Pi.Visible = False
    Next Pi
    On Error GoTo 0

    ' Apply new filters
    For Each value In filterValues
        
            pf.PivotItems(value).Visible = True
        
    Next value
    If IsError(Application.Match(var, filterValues, 0)) Then
        pf.PivotItems(var).Visible = False
    End If
End Sub

Use run macro and pass parameter for macro. just pass the array using string.Join(",",ArrayHere)

This would filter with all values together

PS: Chatgpt helped

cheers