Pivot tables are among the most valuable features that allow users to swiftly summarize and analyze large quantities of data to see comparisons, patterns, and trends in their data. From the 4D v19, pivot tables are included in 4D View Pro. This blog post reviews how to use a pivot table through the ribbon interface.
The video below shows you how to create a pivot table with the ribbon. Each step is described below the video:
Add data
The first step is always to create a data source for your pivot table. In this blog post, we use data from a table in our database. To use it, we add a new sheet named “DataSource” and create in it a new table that contains the data:
$data:=New object("SalesSource"; ds.Sales.all().toCollection())
// Create a new sheet that contains the data
VP ADD SHEET(This.Area; 1; "DataSource")
// Data context creation
VP SET DATA CONTEXT(This.Area; $context; Null; 1)
// Creation of a table that will be used by the table as datasource
VP CREATE TABLE(VP Cell(This.Area; 0; 0; 1); This.TableName; $contextAttribut)
The data is now displayed in a table on the second worksheet in the workbook titled DataSource:
Add a Pivot Table
Now that we have our data in a table, we will add a pivot table. Select your source table in your document and click on the PivotTable button of the ribbon:
It opens a window that allows you to choose where you want to put your pivot table:
There is now a blank pivot table in a new worksheet of your document:
Pivot table side panel
To activate the pivot table side panel, click on the pivot table area, and drag and drop your fields as you need:
Below is an example of a pivot table that you can obtain:
Take a look at the SpreadJS documentation to find all the ways to manage your pivot tables.