Elements inside custom groups act like separate and independent filters; they add different WHERE
and GROUP BY
clauses to the SQL statement generated by the report. The filtering condition can be an attribute qualification as in the previous example, a metric qualification, or other objects. Metric qualifications work like filters on metrics (see Chapter 4, Objects – Facts and Metrics, and Chapter 8, Dynamic Selection with Filters and Prompts, for more details).
I personally use custom groups because they offer a high level of flexibility and may be modified over time, when reporting requirements change, with no need to touch the database schema. As a plus, you can give different formats to different elements.
Another very interesting feature of custom group is the custom banding.
Custom bands are a way to create sets of rows depending on the values of a metric. Typical use can be segmenting customers by purchase brackets or clustering products by number of units sold.
In this recipe we are creating a custom group and a report showing the best-selling bikes that sold more than 1000 units, more than 1200, and so on:
Best selling Products
.1200
.1000
.More than 1000 units
.1400
.More than 1200 units
and click on Add New Band.100000
and name the band More than 1400 units
. Click on a white area to confirm the name, the editor should look like the following screenshot:Best selling Products Custom Group
and click on the Save button.OrderQuantity
and a total for the custom group element Best selling Products
.51 Best selling Bikes Bands
.The name of the custom group element—Best selling Products
—will appear at the top of the first column, then in a hierarchical view, all the names of the bands will appear in a second column.
It's worth noting that lower limits are inclusive while upper limits are not: so the first band in our example is actually between 1000 and 1199, the second between 1200 and 1399, and so on. Adjust the values of the textboxes according to the expected results.
Another aspect that may lead to confusion is that the bands always go from small numbers to big numbers. There is no way to create them in reverse order that is from a higher to a lower value (at least until version 9.3.0).
The Level is actually the GROUP BY
clause of the query: is the Level at which we calculate the OrderQuantity
before filtering those Products that pass the 1000 threshold. Go to SQL View to see how the HAVING
clause is used to restrict the result set.
What if we want to sort the banded products by OrderQuantity
in descending order? It actually makes sense to have the top bikes first in the report grid. Try this:
51 Best selling Bikes Bands DESC
.Create a new fact: OrderQuantity from FactInternetSales
Create a new metric: Sum OrderQuantity from FactInternetSales
Modify Best Selling Products Custom Group, rename the first element to Best selling Products (Resellers)
, and create a second element Best selling Products (Internet)
with similar bands (1000-1200, 1200-1400, 1400-100000) based on the Sum OrderQuantity from FactInternetSales
metric.
Build the report 52 Best Selling Products Reseller and Internet
, like the one in the following image:
Remember to update the schema and to set the custom group element display options.