We continue our series of articles on Data Transformation in Stimulsoft products. Previously, we covered joining tables and calculating running totals. In this article, we will look at data grouping and show how it can be used to obtain aggregated values for reports and dashboards.
As an example, we will use the Chart on Data Band report and the product and category data it contains.

Chart on Data Band report in the designer preview
For example, the data source may contain information about the stock levels of individual products, while we need to obtain the total quantity of products for each category. This task can be performed directly at the data source level, for example, using an SQL query. However, Data Transformation allows you to group the data directly in the reporting tool without modifying the original query.

How data grouping works

Data grouping uses two types of fields: Dimension and Measure. Dimensions define the values by which data is grouped, while measures contain the data that is aggregated within each group.

For example, if you use the CategoryID category identifier as a dimension and UnitsInStock, which stores the number of product units in stock, as a measure and apply the Sum function, you can obtain the total number of product units in stock for each category. You can use multiple dimensions for grouping. For example, data can first be grouped by category and then by individual products within that category.

Grouping in Data Transformation

Open the Dictionary tab, click the New button, and select the New Data Transformation command.

New Data Transformation command in the Dictionary New menu
Add the CategoryID and UnitsInStock fields to the transformation. Set CategoryID to Dimension and UnitsInStock to Measure. For the UnitsInStock measure, select the Sum aggregation function. The data will then be grouped by CategoryID, and the sum of UnitsInStock will be calculated for each category.

Data grouped by CategoryID with the sum of UnitsInStock

Multiple levels of grouping

If necessary, you can make the grouping more detailed by using multiple dimensions. In this example, the Products and Categories tables are related. This means that a single transformation can use the CategoryName category name from the Categories table together with product data from the Products table.

Add the CategoryName, ProductName, and UnitsInStock fields to the transformation. Set CategoryName and ProductName to Dimension, and UnitsInStock to Measure. For UnitsInStock, use the Sum function. As a result, the data will be grouped by products within their respective categories.

Data grouped by CategoryName and ProductName
To obtain the next level of grouping, switch ProductName from Dimension to Measure and apply the Count function to it. CategoryName will remain the only dimension, while UnitsInStock will remain a measure with the Sum function. As a result, for each category you can obtain the number of products it contains and their total quantity in stock. For example, in our case the Beverages category contains 12 products and 559 units in stock.

Number of products and total units in stock for each category
Thus, by changing the set of dimensions, you can control the level of detail in the grouped data.

Working with grouped data

When using other Data Transformation operations, it is important to consider at which stage they are applied – before or after grouping. Some operations can be applied either to the original rows or to already grouped data. For example, when limiting the number of rows, you can specify whether the limit should be applied to the original data or to the grouping result. We will look at these settings in more detail in a separate article in this series.

Conclusion

Grouping in Data Transformation allows you to prepare aggregated data for use in reports and dashboards. Dimensions define the grouping criteria, while measures and aggregation functions are used to calculate the resulting values for each group.
Hi. Need any help?