79143209

Date: 2024-10-31 00:59:45
Score: 1.5
Natty:
Report link

I use Add2 without a problem, however the earlier powersell help files wans't accurate on how to format Add2() correctly. Use the following format.

PivotFilter.Add2(XlPivotFilterType Type, Variant DataField, Variant Value1, Variant Value2, Variant Order, Variant Name, Variant Description, Variant MemberPropertyField, Variant WholeDayFilter)

For XlPivotFilterType Type correct number representing the filter type. For Variant DataField you need to use the full path i.e.: $wb.Sheets('Sheet1').PivotTables("PivotTable01").PivotFields("Count of date") For Variant Value1 use the value you want to filter on.

Here is an example from one of my pulls that filters on a date field to filter on 'Begins with' 2024-05-01.

$wb.Sheets('Sheet1').PivotTables('PivotTable01').PivotFields('date').PivotFilters.Add2(17,$wb.Sheets('Sheet1').PivotTables("PivotTable01").PivotFields("Count of date"), "2024-05-01")

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: FKJr