I have an excel Pivot Table titled PivotTable1. Utilizing Office Scripts I am trying to automate the filtering. There are two columns prescriber and spent amount. I am trying to add a filter to the sum of the spent amount when it’s greater than $325. Essentially trying to automate the filter value function in excel. enter image description here
I think the below Office Script should be similar to what you are trying to do. The Office Script Pivot Table interface is in documentation but there aren't a lot of great samples matching your goals, at least they aren't readily available. I poked around in the forum and swear I saw a previous post with similar question but lost that tab.
function main(workbook: ExcelScript.Workbook)
{
// declare the target pivot table
let moviesPivot = workbook.getPivotTable("PivotTable4");
// declare the field you are filtering
let filterField = moviesPivot.getHierarchy("Title");
// declare the filter to only include rows with budget over...
let filter: ExcelScript.PivotValueFilter = {
condition: ExcelScript.ValueFilterCondition.greaterThan,
comparator: 2000000,
value: "Sum of budget"
};
// apply the value filter to the field
filterField.getPivotField("Title").applyFilter({ valueFilter: filter });
}