Consulting

Results 1 to 10 of 10

Thread: Pivot Table Multiple Value Filter Help

  1. #1
    VBAX Regular
    Joined
    May 2017
    Posts
    49
    Location

    Question Pivot Table Multiple Value Filter Help

    Hi All -

    I created a pivot cache so I can used the same data set to create multiple pivot tables. As I add items to the page field, I want to filter on 3 items out of 10. I tried to use the pivot items set to visible for the three criteria I want to filter on and it's not filtering. If I set the pivot items to false on the criteria I want to filter out, that works. The problem I may face later on is what when the list to filter out items goes to 15 or 20. I don't want to write out each item to filter out. I would rather set the pivot items to be visible for the 3 I want to see. I have attached the snipped of the code and hopefully someone can provide a quick solution. The pivot item field is called "Phase Found In"

    With ActiveSheet
                Lastrow = ActiveSheet.UsedRange.Rows.Count
            End With
    Let copyrange = Lastrow + 8
            
        Set pt = pc.CreatePivotTable( _
            Tabledestination:=Range("A" & copyrange), _
            TableName:="OCE_SEV1_PIVOT")
            
        Set pf = pt.PivotFields("Severity")
        pf.Orientation = xlPageField
        pf.CurrentPage = "Severity 1"
        
        Set pf = pt.PivotFields("Blocking")
        pf.Orientation = xlPageField
        pf.CurrentPage = "Y"
        
        Set pf = pt.PivotFields("Stream")
        pf.Orientation = xlPageField
        pf.CurrentPage = "OCE"
        
        Set pf = pt.PivotFields("Status")
        pf.Orientation = xlPageField
        
        Set pf = pt.PivotFields("Phase Found In")
        pf.Orientation = xlPageField
        pf.EnableMultiplePageItems = True
        pf.ClearAllFilters
        pf.PivotItems("Assembly Test").Visible = False
        pf.PivotItems("Not a Testing Phase").Visible = False
        pf.PivotItems("Performance/Load Testing").Visible = False
        pf.PivotItems("Production Testing").Visible = False
        pf.PivotItems("PVT").Visible = False
        pf.PivotItems("Regression Testing").Visible = False
        pf.PivotItems("Unit Testing").Visible = False
           
        Set pf = pt.PivotFields("Assigned to App")
        pf.Orientation = xlRowField
        
        Set pf = pt.PivotFields("Assigned To Team")
        pf.Orientation = xlColumnField
        
        Set pf = pt.PivotFields("Assigned to App")
        pf.Orientation = xlDataField
        pf.Function = xlCount

  2. #2
    VBAX Tutor MINCUS1308's Avatar
    Joined
    Jun 2014
    Location
    UNDER MY DESK
    Posts
    254
    I have experienced days of frustration while trying to filter pivot tables with macros - I know your pain.
    You might try creating an array of your pivot items and then looping through the array and setting visibility for each item.
    - I HAVE NO IDEA WHAT I'M DOING

  3. #3
    VBAX Tutor MINCUS1308's Avatar
    Joined
    Jun 2014
    Location
    UNDER MY DESK
    Posts
    254
    on a side note... the statement:
    With ActiveSheet 
        Lastrow = ActiveSheet.UsedRange.Rows.Count 
    End With
    Is redundant.
    you should be able to accomplish the same thing with
        Lastrow = ActiveSheet.UsedRange.Rows.Count
    - I HAVE NO IDEA WHAT I'M DOING

  4. #4
    VBAX Regular
    Joined
    May 2017
    Posts
    49
    Location
    Thanks for responding and I hear you. It's a real pain in the arse. Here's what I came up with based on your recommendation but I am getting an error: Compile error: Variable required - can't assign to this expression

     For Each pf.PivotItems In _
            pt.PivotFields("Phase Found In")
            Select Case pf.PivotItems
                Case "Integrated Systems Testing", "User Acceptance Test (UAT)", "End to End Testing (ETE)"
                    pf.PivotItems.Visible = True
                Case Else
                    pf.PivotItems.Visible = False
            End Select
        Next pf.PivotItems

  5. #5
    VBAX Tutor MINCUS1308's Avatar
    Joined
    Jun 2014
    Location
    UNDER MY DESK
    Posts
    254
    ahh...
    The debug is landing on your for statement - correct?
    Not the let statement in your initial post?

    A quick search led me here:
    https://msdn.microsoft.com/VBA/Langu...his-expression

    I think the increment on your loop is the problem.
    Like I said I HATE WORKING WITH PIVOT TABLES because of stupid stuff like this
    - I HAVE NO IDEA WHAT I'M DOING

  6. #6
    VBAX Regular
    Joined
    May 2017
    Posts
    49
    Location
    Correct, the debug is landing on pf.PivotItems

  7. #7
    VBAX Tutor MINCUS1308's Avatar
    Joined
    Jun 2014
    Location
    UNDER MY DESK
    Posts
    254
    I'm positive that there is a "correct" method to resolving your problem #GuruPleaseHelpMe!
    As my tag line reads: I have no idea what I'm doing...

    But there is always more than one way to skin a cat.
    Somewhere you have data that is your "pivotitems".
    You could step through the data and create an array of the items.
    Then step through your array just as you tried to do with the pivot Items.
    Its not pretty but that would work.
    - I HAVE NO IDEA WHAT I'M DOING

  8. #8
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Quote Originally Posted by BenChod View Post
    Thanks for responding and I hear you. It's a real pain in the arse. Here's what I came up with based on your recommendation but I am getting an error: Compile error: Variable required - can't assign to this expression

     For Each pf.PivotItems In _
            pt.PivotFields("Phase Found In")
            Select Case pf.PivotItems
                Case "Integrated Systems Testing", "User Acceptance Test (UAT)", "End to End Testing (ETE)"
                    pf.PivotItems.Visible = True
                Case Else
                    pf.PivotItems.Visible = False
            End Select
        Next pf.PivotItems


    The For Each loop is wrong

    Not tested, but try something like this

    Dim PI as PivotItem
    
    For Each PI in In pt.PivotFields("Phase Found In") .PivotItems
    
        Select Case PI.Caption
    
        Case "Integrated Systems Testing", "User Acceptance Test (UAT)", "End to End Testing (ETE)" 
            PI.Visible = True 
        Case Else 
            PI.Visible = False 
        End Select 
    
    Next
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  9. #9
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    Can you post a workbook with enough dummy data to show the issue?

    This seems to be the area causing problems??

    Set pf = pt.PivotFields("Phase Found In") 
    pf.Orientation = xlPageField 
    pf.EnableMultiplePageItems = True 
    pf.ClearAllFilters 
    pf.PivotItems("Assembly Test").Visible = False 
    pf.PivotItems("Not a Testing Phase").Visible = False 
    pf.PivotItems("Performance/Load Testing").Visible = False 
    pf.PivotItems("Production Testing").Visible = False 
    pf.PivotItems("PVT").Visible = False 
    pf.PivotItems("Regression Testing").Visible = False 
    pf.PivotItems("Unit Testing").Visible = False

    I did a very simple Recorder macro and it seems to work so maybe something else is happening

    Sub Macro1()
        With ActiveSheet.PivotTables("PivotTable1").PivotFields("AAA")
            .EnableMultiplePageItems = True
            .CurrentPage = "(All)"
            .PivotItems("A").Visible = False
            .PivotItems("C").Visible = False
            .PivotItems("E").Visible = False
        End With
    End Sub
    Capture.JPG
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  10. #10
    VBAX Regular
    Joined
    May 2017
    Posts
    49
    Location
    Thanks, that worked. Really appreciate the help. Now I don't have to list out all items that I want to exclude.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •