workbook.createPivot(options)

Note:

The content in this help topic applies to SuiteScript 2.x.

Method Description

Creates a pivot.

A pivot is a workbook component that enables you to pivot your dataset query results by defining measures and dimensions, so that you can analyze different subsets of data. A pivot definition is based on an underlying dataset and can include an ID, a name, a row axis, a column axis, conditional/limiting filters, and filter expressions.

Returns

workbook.Pivot

Supported Script Types

Server scripts

For more information, see SuiteScript 2.x Script Types.

Governance

None

Module

N/workbook Module

Sibling Module Members

N/workbook Module Members

Since

2020.2

Parameters

Note:

The options parameter is a JavaScript object.

Parameter

Type

Required / Optional

Description

options.aggregationFilters

Array<workbook.ConditionalFilter |workbook.LimitingFilter>

optional

The set of conditional filters or limiting filters that are applied to the pivot. When multiple filters are defined, they are aggregated together to form a single compounded filter.

options.columnAxis

workbook.PivotAxis

required

The column axis (X-axis) for the pivot. This includes the fields and measures that are used on the column axis, as well as sorting behavior that is applied to the axis fields and measures.

options.dataset

dataset.Dataset

required

The underlying dataset that the pivot is based on. A pivot can include only the data (fields) that are included in the dataset.

options.filterExpressions

workbook.Expression[]

optional

The simple, non-aggregated value-based filters for the pivot.

options.id

string

required

The ID of the pivot.

options.name

string

required

The name of the pivot.

options.reportStyles

workbook.ReportStyle

required

The report styles for the pivot.

options.rowAxis

workbook.PivotAxis

required

The row axis (Y-axis) for the pivot. This includes the fields and measures that are used on the column axis, as well as sorting behavior that is applied to the axis fields and measures.

Syntax

Important:

The following code sample shows the syntax for this member. It is not a functional example. For a complete script example, see N/workbook Module Script Samples.

            // Add additional code
...
// Create a basic PivotDefinition
var myPivotDefinition = workbook.createPivotDefinition({
    name: 'My Pivot Definition',
    id: '_myPivotDefinition',
    rowAxis: myRowPivotAxis,
    columnAxis: myColumnPivotAxis,
    dataset: myDataset
});

// Create a comprehensive PivotDefinition with Expressions
var myPivotDefinition = workbook.createPivotDefinition({
    name: 'My Pivot Definition',
    id: '_myPivotDefinition',
    rowAxis: myRowPivotAxis,
    columnAxis: myColumnPivotAxis,
    dataset: myDataset,
    filterExpressions: [myExpression]
});

// Create a comprehensive PivotDefinition with LimitingFilters
var myPivotDefinition = workbook.createPivotDefinition({
    name: 'My Pivot Definition',
    id: '_myPivotDefinition',
    rowAxis: myRowPivotAxis,
    columnAxis: myColumnPivotAxis,
    dataset: myDataset,
    filterExpressions: [myExpression],
    aggregationFilters: [myLimitingFilter]
});

// Create a comprehensive PivotDefinition with ConditionalFilters
var myPivotDefinition = workbook.createPivotDefinition({
    name: 'My Pivot Definition',
    id: '_myPivotDefinition',
    rowAxis: myRowPivotAxis,
    columnAxis: myColumnPivotAxis,
    dataset: myDataset,
    filterExpressions: [myExpression],
    aggregationFilters: [myConditionalFilter]
});
...
// Add additional code 

          

Related Topics

N/workbook Module
SuiteScript 2.x Modules
SuiteScript 2.x

General Notices