Filter Pivot Row based on Multiple Measures

DaveBlakeMAAT

Board Regular
Joined
Feb 28, 2016
Messages
190
Hi,

I am hoping one of you fine people can assist, I am using VBA with a data model to draw Pivot Tables (the data is loaded to PowerQuery Only and saved as a connection). Drawing the Pivots was fine once i got my head around the nuances of CubeFields with the help of trusty WiseOwl videos!

The problem i have is how to filter a row based on multiple Measure criteria (The IF Statement in the code below), and how to then define if the row is visible (not sure if pi.Visible = TRUE would work).

VBA Code:
Sub FilterCostCentresWhereNoSpend()

Dim pt As PivotTable
Dim pf As PivotField
Dim pi As PivotItem
       
         Set pt = ActiveSheet.PivotTables("ptRunRateByCostCentre")
         Debug.Print pt
        
        Set pf = pt.PivotFields("[RunRateData].[Cost Centre Description].[Cost Centre Description]")
       
        For Each pi In pf.PivotItems
       
            If Measure1.value = 0 And Measure2.value = 0 Then
                Debug.Print pi
               
                pi.Visible = False
            Else
                pi.Visible = True
            End If
           
        Next pi
End Sub

Any Help is greatly appreciated!

Regards

Dave
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top