4D View Pro: Create a Pivot Table from a data table

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.

Fabrice Mainguené
• Product Owner •Fabrice Mainguené joined 4D Program team in November, 2016. As a Product Owner, he is in charge of writing the user stories then translating it to functional specifications. His role is also to make sure that the feature implementation delivered is meeting the customer need.After obtaining a Bachelor degree in Computer Science at CNAM, Fabrice joined a small software publishing company as a Windev developer. Then he worked for different companies in industry and trade areas as a Windev and web developer as well as technical advisor on new features.