Excel.ShowAsCalculation enum

The ShowAs calculation function for the DataPivotField.

Remarks

[ API set: ExcelApi 1.8 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/38-pivottable/pivottable-calculations.yaml

await Excel.run(async (context) => {
    const pivotTable = context.workbook.worksheets.getActiveWorksheet().pivotTables.getItem("Farm Sales");
    const farmDataHierarchy: Excel.DataPivotHierarchy = pivotTable.dataHierarchies.getItem("Sum of Crates Sold at Farm");        
    const wholesaleDataHierarchy: Excel.DataPivotHierarchy = pivotTable.dataHierarchies.getItem("Sum of Crates Sold Wholesale");

    farmDataHierarchy.load("showAs");
    wholesaleDataHierarchy.load("showAs");
    await context.sync();

    // Show the crates of each fruit type sold at the farm as a percentage of the column's total.
    let farmShowAs = farmDataHierarchy.showAs;
    farmShowAs.calculation = Excel.ShowAsCalculation.percentOfColumnTotal;
    farmShowAs.baseField = pivotTable.rowHierarchies.getItem("Type").fields.getItem("Type");
    farmDataHierarchy.showAs = farmShowAs;

    let wholesaleShowAs = wholesaleDataHierarchy.showAs;
    wholesaleShowAs.calculation = Excel.ShowAsCalculation.percentOfColumnTotal;
    wholesaleShowAs.baseField = pivotTable.rowHierarchies.getItem("Type").fields.getItem("Type");
    wholesaleDataHierarchy.showAs = wholesaleShowAs;
    await context.sync();
});

Fields

differenceFrom = "DifferenceFrom"

Difference from the specified Base field and Base item.

index = "Index"

Calculates the values as follows: ((value in cell) x (Grand Total of Grand Totals)) / ((Grand Row Total) x (Grand Column Total))

none = "None"

No calculation is applied.

percentDifferenceFrom = "PercentDifferenceFrom"

Difference from the specified Base field and Base item.

percentOf = "PercentOf"

Percent of the specified Base field and Base item.

percentOfColumnTotal = "PercentOfColumnTotal"

Percent of the column total.

percentOfGrandTotal = "PercentOfGrandTotal"

Percent of the grand total.

percentOfParentColumnTotal = "PercentOfParentColumnTotal"

Percent of the column total for the specified Base field.

percentOfParentRowTotal = "PercentOfParentRowTotal"

Percent of the row total for the specified Base field.

percentOfParentTotal = "PercentOfParentTotal"

Percent of the grand total for the specified Base field.

percentOfRowTotal = "PercentOfRowTotal"

Percent of the row total.

percentRunningTotal = "PercentRunningTotal"

Percent running total of the specified Base field.

rankAscending = "RankAscending"

Ascending rank of the specified Base field.

rankDecending = "RankDecending"

Descending rank of the specified Base field.

runningTotal = "RunningTotal"

Running total of the specified Base field.

unknown = "Unknown"

Calculation is unknown or unsupported.