Transforming Raw Data with Pivot Table Aggregation
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (175).NET Core  (29).NET MAUI  (208)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (220)BoldSign  (15)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (67)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (101)Streamlit  (1)Succinctly series  (131)Syncfusion  (920)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (37)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (151)Chart  (132)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (633)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (41)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (508)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (11)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (597)What's new  (333)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Transforming Raw Data with Pivot Table Aggregation

Transforming Raw Data with Pivot Table Aggregation

A pivot table puts together raw data from various data sources that are normally flat, resulting in many individual and detailed records that are unorganized. When raw data lacks structure, it isn’t easy to understand for any user.

This is where the Syncfusion JavaScript Pivot Table’s data aggregation feature comes in. This feature converts raw data into summarized and organized data using a pivot engine. The data is then bound to a pivot table UI for viewing the well-structured and understandable result.

Let’s explore this powerful and user-friendly feature with code examples.

Aggregation types

The most popular aggregation types supported by the JavaScript Pivot Table are:

  • Sum
  • Product
  • Count
  • Distinct Count
  • Min
  • Max
  • Average

Other types of aggregations are:

  • Median
  • Index
  • PopulationStDev
  • SampleStDev
  • PopulationVar
  • SampleVar
  • RunningTotals
  • DifferenceFrom
  • PercentageOfDifferenceFrom
  • PercentageOfGrandTotal
  • PercentageOfColumnTotal
  • PercentageOfRowTotal
  • PercentageOfParentTotal
  • PercentageOfParentColumnTotal
  • PercentageOfParentRowTotal

Use case

Let’s look at a real-time scenario in a supermarket. Many sales occur there throughout the day. Every sale will be treated as a separate record added to the database, which is our raw data. It would be difficult to analyze product sales using raw data alone, and this raw data must be converted to a structured, organized format.

For instance, take the product Polo T-Shirt. If an analyst wants to know the minimum or maximum number of polo t-shirt purchases per month, quarter, or year, they can use the Min and Max aggregates. If the analyst wants to know the average sales of t-shirts per month, quarter, or year, they can use the Avg aggregate.

Points to remember

Before diving deep into data aggregation in our JavaScript Pivot Table, remember the following points:

  • Despite the fact that the Pivot Table supports many aggregation types, fields with data types such as numbers support all the listed aggregation types. Meanwhile, the fields with data types such as string, date, datetime, and Boolean support only count and distinct count aggregation types.
  • By default, the aggregation type will be Sum for number-type fields and Count for non-number-type fields.
  • The aggregation types are available only for fields in the Values section.

Getting started with data aggregation in JavaScript Pivot Table

The aggregation type can be set to a field in the Pivot Table via:

  • UI option: Changes the aggregation type dynamically at runtime.
  • Code-behind: Displays the aggregated field in the pivot table during initial loading.

Perform data aggregation via UI

 To do the data aggregation via UI, use the dropdown arranged inside the Values section.

Dropdown to view the aggregation type
Dropdown to view the aggregation type

A list of basic aggregation types will appear, which can be selected from and changed at runtime.

Menu from which to select the aggregation type
Menu from which to select the aggregation type

Click the More option at the bottom of the context menu. It opens a dialogue with advanced aggregation settings to handle a field based on your requirements.

Advanced aggregation settings in JavaScript Pivot Table
Advanced aggregation settings in JavaScript Pivot Table

So, these are the primary steps for dynamically changing an aggregation type for any field at runtime via UI.

Perform data aggregation via code-behind

To do the data aggregation via code-behind, in the Values section, first define the field with its name and caption.

The type property then accepts the assigned aggregate type and processes it in the pivot engine before providing the result data to render the pivot table UI.

Refer to the following code example. In it, we have used the aggregation type Avg.

import { PivotView, IDataSet } from '@syncfusion/ej2-pivotview';
import { pivotData } from './datasource.ts';

let pivotTableObj: PivotView = new PivotView({
    dataSourceSettings: {
        dataSource: pivotData as IDataSet[],
        columns: [{ name: 'EnerType', caption: 'Energy Type' }, { name: 'EneSource', caption: 'Energy Source' }],
        values: [{ name: 'PowUnits', caption: 'Units (GWh)', type: 'Avg' }, { name: 'ProCost', caption: 'Cost (MM)' }],
        rows: [{ name: 'Year', caption: 'Production Year' }, { name: 'Quarter', caption: ' Quarter Year' }],
        filters: []
    }
});
pivotTableObj.appendTo('#PivotTable');

Refer to the following images.

Units (GWh) field with Sum aggregation (default)
Units (GWh) field with Sum aggregation (default)
Units (GWh) field with Avg aggregation
Units (GWh) field with Avg aggregation

Customization options

The JavaScript Pivot Table’s data aggregation feature comes with more options:

  • The ability to show or hide the UI icon allows us to dynamically change the aggregation type at runtime. By default, the UI icon will be displayed.
  • Rather than displaying all aggregation types in the context menu, one can display only the desired types.
  • The ability to edit the aggregation text in the UI. For example, “Sum of Units Sold” can be displayed as “Units Sold” as well.

References

For more details, refer to the Aggregation in JavaScript Pivot Table demos and documentation.

Conclusion

Thanks for reading! This blog explored the data aggregation feature in the Syncfusion JavaScript Pivot Table. With this feature, we can convert raw data into summarized and organized data to get clear insights from it.

We strongly urge you to explore our Syncfusion Essential JS 2 suite, which boasts over 80 user-friendly JavaScript UI controls. Your feedback is essential to us, and we encourage you to share your thoughts in the comments section below.

Existing customers can access the newest version of Essential Studio from the License and Downloads page. If you’re not a customer yet, we offer a 30-day free trial to let you experience the full range of available features.

If you have questions, you can contact us through our support forumsupport portal, or feedback portal. Our team is always eager to help you.

Related blogs

Tags:

Share this post:

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed