Easily Group Data into Ranges in Web Applications Using Pivot Table
Tags: webdev, pivottable, grouping, productivity
Published: 2023-02-10 12:34:51

---
title: Easily Group Data into Ranges in Web Applications Using Pivot Table
published: true
date: 2023-02-09 12:28:28 UTC
tags: webdev, pivottable, grouping, productivity
canonical_url: https://www.syncfusion.com/blogs/post/easily-group-data-into-ranges-in-web-applications-using-pivot-table.aspx
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wr5oahyu5migejgcwqa3.png
---
Frequency distribution categorizes and positions input data in appropriate groups. This occurs in ranges for better statistical analysis. A pivot table is a type of component that allows users to categorize and view input data like in a frequency distribution table. You can group date, number, and text fields in a pivot table into ranges.

For example:

- We can group the birth rate around the world over the last three years, quarter by quarter (date type), into 2019 (Q1, Q2, Q3, Q4), 2020 (Q1, Q2, Q3, Q4), and 2021 (Q1, Q2, Q3, Q4).
- We can divide the world population into age groups (number type) such as 0-20, 21-40, 41-60, 60-and-above.
- We can also group populations of countries (string type) into the continents of North America, South America, Europe, Asia, Africa, and Australia.

In this blog, we will walk through how to group data into ranges with a real-time scenario.

## Group data using date and time

To begin with, we will group data based on date and time ranges. In this illustration, we will see YouTube videos published by a channel in English and Hindi and the number of likes and comments for them during specific time periods.

First, insert the **Years** field into the pivot table’s **row** axis, the **Language of the Video** field into the **column** axis, and **Video URL** (to get the number of videos), **Likes** , and   **Comments** into the **value** axis.

When you right-click on the **Years** field, a context menu with the option Group appears. When you select **Group** , a dialog appears in which you can enter the start and end dates, as well as the interval type. Since we are grouping by date type, the Interval dropdown will display the following options: years, quarters, months, days, hours, minutes, and seconds. As a result, we will get the following output.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/02/Group-option-in-the-context-menu-to-group-by-date-and-time.png" alt="Group option in the context menu to group by date and time" style="width:100%">

  <figcaption>Group option in the context menu to group by date and time</figcaption>

</figure>

<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/02/Group-dates-from-2005-to-the-present-by-year-quarter-and-month.png" alt="Group dates from 2005 to the present by year, quarter, and month" style="width:100%">

  <figcaption>Group dates from 2005 to the present by year, quarter, and month</figcaption>

</figure>

<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/02/Pivot-Table-displaying-YouTube-video-details-organized-by-date-and-time.png" alt="Pivot Table displaying YouTube video details organized by date and time" style="width:100%">

  <figcaption>Pivot Table displaying YouTube video details organized by date and time</figcaption>

</figure>

**Note:** By default, the dates excluded from the date range will be grouped under the Out of Range category. We can also customize the name Out of Range.

## Group data using number type

Following the date and time is the number type. In this illustration, we will see used car sales divided into ranges of kilometers driven for various car brands. To make the classification, the number of cars in these ranges are tabulated along with sales amount details: 0–100,000 kms, 100,001–200,000 kms, 200,001–300,000 kms, and greater than 300,000 kms.

To do this, insert the **kms Driven** field in the pivot table’s column axis, **Car Name** in the row axis, and **No. of cars sold** and **Sold amount** in the value axis.

When you right-click the **kms Driven** field, a context menu with the Group option will appear. When you select **Group** , a dialog appears in which you can enter the start and end numbers, as well as the interval count. Refer to the following output images.

<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/02/Group-option-in-the-context-menu-to-group-by-kilometers.png" alt="Group option in the context menu to group by kilometers" style="width:100%">

  <figcaption>Group option in the context menu to group by kilometers</figcaption>

</figure>

<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/02/Kilometers-from-0-to-300000-are-divided-into-groups-of-100000.png" alt="Kilometers from 0 to 300,000 are divided into groups of 100,000" style="width:100%">

  <figcaption>Kilometers from 0 to 300,000 are divided into groups of 100,000</figcaption>

</figure>

<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/02/Pivot-Table-displaying-information-about-used-car-sales.png" alt="Pivot Table displaying information about used car sales" style="width:100%">

  <figcaption>Pivot Table displaying information about used car sales</figcaption>

</figure>

**Note:** By default, the numbers excluded will be grouped under the Out of Range category. The name Out of Range can be customized.

## Group data by string type

Finally, we’ll use the custom format to format the string data type. To illustrate this, we will return to the previous example of used car sales, where car names of string data type are grouped based on their brand name.

Insert the **kms Driven** field in the pivot table’s column axis, **Car Name** in the row axis, **No. of cars sold** and **Sold amount** in the value axis.

To group the custom format field members, select the appropriate header(s) by holding down the **Ctrl** or **Shift** key and right-clicking; a context menu with the option Group appears. When you select **Group,** a dialog box appears in which you can enter the field caption and group name **.** In our illustration, we enter **Brand** in the field caption and **Audi** in the group name **,** resulting in the creation of a new field, Brand, in the row axis on top of the Car Name field. And the selected header(s) are added to the group created under the group name Audi. We get the following output.

<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/02/Pivot-Table-displaying-information-about-used-car-sales-1.png" alt="Pivot Table displaying information about used car sales" style="width:100%">

  <figcaption>Pivot Table displaying information about used car sales</figcaption>

</figure>

<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/02/Group-option-in-the-context-menu-to-group-Audi-car-names.png" alt="Group option in the context menu to group Audi car names" style="width:100%">

  <figcaption>Group option in the context menu to group Audi car names</figcaption>

</figure>

<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/02/With-the-new-Brand-field-group-car-names-under-the-name-Audi.png" alt="With the new Brand field, group car names under the name Audi" style="width:100%">

  <figcaption>With the new Brand field, group car names under the name Audi</figcaption>

</figure>

<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/02/Pivot-Table-displaying-all-Audi-car-names-grouped-under-Audi.png" alt="Pivot Table displaying all Audi car names grouped under Audi" style="width:100%">

  <figcaption>Pivot Table displaying all Audi car names grouped under Audi</figcaption>

</figure>

Audi car names are now grouped under one name, Audi, while other car names are listed under their names, such as Ambassador CLASSIC 1500 DSL AC, on top of Audi. You can group Ambassador cars under their brand. To do so, expand the appropriate headers and select the car names. As usual, right-click and select **Group**. Retype **Brand** in the field caption and **Ambassador** in the group name.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/02/Group-option-in-the-context-menu-to-group-other-car-names-by-brand..png" alt="Group option in the context menu to group other car names by brand" style="width:100%">

  <figcaption>Group option in the context menu to group other car names by brand</figcaption>

</figure>

<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/02/With-the-existing-Brand-field-group-car-names-under-the-Ambassador-brand.png" alt="With the existing Brand field, group car names under the Ambassador brand" style="width:100%">

  <figcaption>With the existing Brand field, group car names under the Ambassador brand</figcaption>

</figure>

You can do the same for all other car names, and the end result is shown in the following images.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/02/Pivot-Table-displaying-information-on-used-car-sales-by-brand.png" alt="Pivot Table displaying information on used car sales by brand" style="width:100%">

  <figcaption>Pivot Table displaying information on used car sales by brand</figcaption>

</figure>

<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/02/Pivot-Table-displaying-information-on-used-car-sales-by-brand-2.png" alt="Pivot Table displaying information on used car sales by brand" style="width:100%">

  <figcaption>Pivot Table displaying information on used car sales by brand</figcaption>

</figure>

## Ungrouping

You can ungroup applied date, number, and string grouping by right-clicking the appropriate header and selecting **Ungroup** from the context menu in the Pivot Table.
<figure>

  <img src="https://www.syncfusion.com/blogs/wp-content/uploads/2023/02/Clearing-the-grouped-data-using-the-context-menu-UI.png" alt="Clearing the grouped data using the context menu UI" style="width:100%">

  <figcaption>Clearing the grouped data using the context menu UI</figcaption>

</figure>

## Editing groups

You can edit the date- and number-based grouping by right-clicking and selecting **Group** from the context menu. The existing grouping information is preserved (state persisted) and we can modify that at any time.

In the case of a custom format, such as string, we have to remove the newly created field, and restart grouping from the beginning. There is no direct edit or modify option for the custom format.

## Documentation references

- TypeScript: [Grouping in JavaScript Pivot Table control](https://ej2.syncfusion.com/documentation/pivotview/grouping/#grouping "Getting Started with Grouping in JavaScript Pivot Table Control")
- JavaScript: [Grouping in JavaScript Pivot Table control](https://ej2.syncfusion.com/javascript/documentation/pivotview/grouping/ "Getting Started with Grouping in JavaScript (ES5) Pivot Table control")
- Angular: [Grouping in Angular Pivot Table component](https://ej2.syncfusion.com/angular/documentation/pivotview/grouping/ "Getting Started with Grouping in Angular Pivot Table Component")
- React: [Grouping in React Pivot Table component](https://ej2.syncfusion.com/react/documentation/pivotview/grouping/ "Getting Started with Grouping in React Pivot Table Component")
- Vue: [Grouping in Vue Pivot Table component](https://ej2.syncfusion.com/vue/documentation/pivotview/grouping/ "Getting Started with Grouping in Vue Pivot Table Component")
- ASP.NET Core: [Grouping in ASP.NET Core Pivot Table control](https://ej2.syncfusion.com/aspnetcore/documentation/pivot-table/grouping "Getting Started with Grouping in ASP.NET Core Pivot Table Control")
- ASP.NET MVC: [Grouping in ASP.NET MVC Pivot Table component](https://ej2.syncfusion.com/aspnetmvc/documentation/pivot-table/grouping "Getting Started with Grouping in ASP.NET MVC Pivot Table Component")

## Conclusion

We hope this article gave you a better understanding of grouping data into ranges in the Pivot Table. Try it out and leave your feedback in the comments section.

Thanks for reading!

Our Pivot Table is available in our [Blazor](https://www.syncfusion.com/blazor-components/blazor-pivot-table "Syncfusion Blazor Pivot Table"), ASP.NET ([Core](https://www.syncfusion.com/aspnet-core-ui-controls/pivot-table "Syncfusion ASP.NET Core Pivot Table"), [MVC](https://www.syncfusion.com/aspnet-mvc-ui-controls/pivot-table "Syncfusion ASP.NET Core Pivot Table"), [Web Forms](https://www.syncfusion.com/jquery/aspnet-web-forms-ui-controls/pivot-grid "Syncfusion ASP.NET Web Forms Pivot Grid")), [JavaScript](https://www.syncfusion.com/javascript-ui-controls/js-pivot-table "Syncfusion JavaScript Pivot Table"), [Angular](https://www.syncfusion.com/angular-ui-components/angular-pivot-table "Syncfusion Angular Pivot Table"), [React](https://www.syncfusion.com/react-ui-components/react-pivot-table "Syncfusion React Pivot Table"), and [Vue](https://www.syncfusion.com/vue-ui-components/vue-pivot-table "Syncfusion Vue Pivot Table") component suites. Use it to organize and summarize business data elegantly in any application!

For existing customers, the newest version of Essential Studio is available for download from the [License and Downloads](https://www.syncfusion.com/account/downloads "License and download page of Essential Studio") page. If you are not yet a Syncfusion customer, you can try our 30-day [free trial](https://www.syncfusion.com/downloads "Free evaluation of the Syncfusion Essential Studio") to check out the available features.

For questions, you can contact us through our [support forum](https://www.syncfusion.com/forums "Syncfusion Support Forum"), [support portal](https://support.syncfusion.com "Syncfusion Support Portal"), or [feedback portal](https://www.syncfusion.com/feedback/ "Syncfusion Feedback Portal"). We are always happy to assist you!

## Related blogs

- [Server-Side Engine in JavaScript Pivot Table: An Overview](https://www.syncfusion.com/blogs/post/server-side-engine-in-javascript-pivot-table.aspx "Blog: Server-Side Engine in JavaScript Pivot Table: An Overview")
- [How to Bind Remote Data and Enable Virtual Scrolling in JavaScript Pivot Table](https://www.syncfusion.com/blogs/post/bind-remote-data-and-enable-virtual-scrolling-in-javascript-pivot-table.aspx "Blog: How to Bind Remote Data and Enable Virtual Scrolling in JavaScript Pivot Table")
- [CSV Data Sources in Blazor Pivot Table: A Groundbreaking Feature](https://www.syncfusion.com/blogs/post/csv-data-sources-in-blazor-pivot-table-a-groundbreaking-feature.aspx "Blog: CSV Data Sources in Blazor Pivot Table: A Groundbreaking Feature")
- [Tips and Tricks to Quickly Render the Pivot Table for Web](https://www.syncfusion.com/blogs/post/tips-and-tricks-to-quickly-render-the-pivot-table.aspx "Blog: Tips and Tricks to Quickly Render the Pivot Table for Web")