How it works
Pivot tables can be generated for a specific search result. In general, creating a pivot table consists in selecting the table's rows and columns and specify what aggregation function (e.g. sum, average, count) is to be applied to the data in the table.
Examples of aggregate functions are:
cardinality – how many times a given value occurs in the set
minimum – the smallest value in the set
maximum – the largest value in the set
sum – the sum of the values in the set
average – the average value of the data in the set.
The method of generating a pivot table can be described as follows:
Given a set of X objects, obtained as a result of the search. All objects are of a specific type, described by a certain set of features (attributes)
Columns and rows are assigned specific attributes
To each cell a subset of X is created, so that the values of the attributes of the subset elements correspond to the values assigned to the columns and rows
An aggregation function (e.g. sum), will be applied to a given subset in a a given cell
Thanks to this, the aggregated value will be displayed in a given cell (e.g. a sum on a given attribute.
Example
As an example, consider a table for objects of type PERSONS.
First name and last name | Affiliation | Status |
Jan Kowalski | Faculty of Architecture | employee |
Adam Nowak | Faculty of Electrical Engineering | pensioner |
Anna Kowalska | Faculty of Management | employee |
Olga Nowak | Faculty of Electrical Engineering | PhD student |
Piotr Kowalski | Faculty of Architecture | employee |
Łukasz Nowak | Faculty of Electrical Engineering | pensioner |
Marta Kowalska | Faculty of Management | employee |
Monika Nowak | Faculty of Electrical Engineering | PhD student |
Henryk Kowalski | Faculty of Architecture | employee |
Jakub Nowak | Faculty of Electrical Engineering | pensioner |
Iwona Kowalska | Faculty of Management | employee |
Jolanta Nowak | Faculty of Electrical Engineering | PhD student |
The features describing people include the Affiliation attribute, which assigns the scientist to one of the university's departments, and Status attribute with the values { employee, retiree, doctoral student }. Let's assume that we want to create a table for employees showing how many employees have a specific status in individual departments. To obtain such a table, we follow the sequence of steps:
We are looking for university employees
Assuming that the pivot will contain the employee's status in the columns and the department affiliation in the rows, we select the Status attribute to build the columns and the Affiliation attribute to create the rows.
As the aggregation function, we will choose the cardinality of the set - how many times a given value occurs in a given subset belonging to the cell.
For the parameters selected in this way, a table will be created as below. In the cell in the Faculty of Architecture row and in the employee column we will receive the number of scientists from the Faculty of Architecture with the status of employee, retiree, doctoral student.
| employee | pensioner | PhD student |
Faculty of Architecture | 3 | 0 | 0 |
Faculty of Electrical Engineering | 0 | 3 | 3 |
Faculty of Management | 3 | 0 | 0 |