Background: As shown in the figure, this is a dataset at the order level, containing detailed data for each order, including order ID, the province where the order occurred, order amount, and more.
Requirement: Aggregate by province to calculate the total sales amount (sum of payment amounts) for each province, and view the distribution of this data (that is, the sales amount for each province). Distribution: View the distribution within the following ranges: 0–200,000, 200,000–400,000, 400,000–600,000, 600,000–800,000, 800,000–1,000,000, and above 1,000,000. In other words, check how many provinces have sales amounts that fall within each of these ranges.
The main challenge in this case is that the dataset is at the order level, while the required distribution data is at the province level. Therefore, it is necessary to aggregate by province first, and then perform a secondary process to view the distribution data.
The aggregation approach is as follows:
(1) Specify aggregation by province and calculate the sum of payment amounts to create the "payment amount by province" field
(2) Use the grouping function to segment the payment amount by province: 0–200,000, 200,000–400,000, 400,000–600,000, 600,000–800,000, 800,000–1,000,000, and above 1,000,000
(3) Use the segmented payment amount by province field as a dimension, and calculate the distinct count of provinces, that is, the number of provinces
(1) Create the "payment amount by province" field
Specify aggregation by the [Province] dimension, calculate the sum of [Payment Amount], and save it as a dimension. The expression is:
{fixed [Province]: sum([Payment Amount])}
(2) Segment the payment amount by province
Select the field and Configure Field Grouping
Group by step size, and set the name and condition for each group as required
(3) Calculate the number of provinces in each segment
Use the above grouping field as a dimension, drag the "Province" field to the metrics area, and select "distinct count" as the aggregation method for the metric.
Select the bar chart as the chart type, and set the sorting as needed.