Aggregating results with custom groups

Custom groups are another type of object that allow us to aggregate results on a report or document. They differ from consolidations in several aspects, the most important being that the SQL needed to calculate custom groups is executed on the RDBMS side.

Unlike consolidations, custom groups cannot perform row-level calculations; but they offer a lot of flexibility when defining the elements. A custom group element is a set of rows identified by a name and a filter condition. Thinking about the previous example: instead of manually picking all the 14 London elements of the City attribute, we would create a filter that restricts only those elements with the DESC form beginning with London.

Additionally, in the filter definition of a custom group element, we can use metrics, like in "Products of the Bike Category that sold more than 1500 units", and display results in bands like in "Bikes that sold from 1000 to 1199 units, from 1200 to 1299, 1300 units or more, etc."

Furthermore, we can expand the custom group elements and see, for example, every bike inside a band.

It is useful to think about custom groups as a collection of mini-reports stacked one above the other, each mini-report having its own filtering conditions.

Getting ready

You need to have completed the previous recipe to continue.

How to do it...

In this recipe, we will create the same UK Areas as we did before, so that we see the difference in generated SQL; later we'll move on to create a more complex custom group:

  1. Go to My Objects folder, right-click on an empty area, and select New | Custom Group from the context menu. Leave default Empty Custom Group and click on OK.
  2. This is the Custom Group Editor (similar to the Filter Editor); maximize the window to have sufficient space.
  3. In the Object Browser pane on the left, double-click on Geography to list the attributes in the hierarchy.
  4. The right part of the editor is the Custom Group definition pane. Drag the City attribute from the left list and drop it onto the area on the right with the text Double-click here or drag an object from the object browser to add a custom group element.
  5. A new custom group element is created with an attribute qualification on City; in the lower-right part of the screen click on the Qualify on drop-down list and select DESC.
  6. From the Operator list, choose Begins with.
  7. Leave the Value option selected, and in the textbox to the right type London, then confirm with OK. Now the Custom Group Editor shows one element named Custom Group Element1 containing a filter definition City (DESC) Begins with London.
  8. Right-click on Custom Group Element1 and from the context menu that appears select Rename. Type London Area.
  9. Move to the left and double-click on the Country attribute to see the list of countries, pick the United Kingdom element, drag it to the right and drop it on the line that says Double-click here or drag an object from the object browser to add a custom group element, the Custom Group element2 is created with a filter definition Country in list (United Kingdom).
  10. In the Object Browser pane, click on the button with the icon that resembles a folder with a green up arrow (tool tip: View contents one level up):
    How to do it...
  11. We're back in the attribute list, click on City, drag-and-drop it to the red [Add Qualification] line just below the Country in list (United Kingdom) to create a second filter definition on City.
  12. Repeat steps 5, 6, and 7. A new filter definition < Default > - City (DESC) Begins with London is added with the AND operator.
  13. Right-click on AND, select Toggle Operator from the menu and choose AND NOT.
  14. Right-click on the Custom Group Element2 line and rename it as Rest of UK.
  15. The final Custom Group definition should look like the image:
    How to do it...
  16. Click on Save and Close. Go to My Reports folder, create a blank new report.
  17. Click on My Personal Objects shortcut, double-click on My Objects, then right-click on UK Areas Custom Group and select Add to Rows.
  18. Browse to Public Objects | Metrics and add Sum SalesAmount from FactResellerSales to columns. Run in Grid View and check the numbers with the report we did in the previous recipe.
  19. Save the new report without closing it and name it 50 UK Sales with Custom Groups.
  20. Switch to SQL View. Note the difference between this report and the previous in terms of SELECT statements. Close both reports.

How it works...

Custom groups generate at least one query per element. In this case you can see the first SELECT filtering on:

where (a13.City + ' ' + a13.PostalCode) like N'London%'

And the second statement with:

where (a13.CountryRegionCode in (N'GB')and (not (a13.City + ' ' + a13.PostalCode) like N'London%'))

In the previous report, the consolidation used a single SQL to produce the same result.

From a RDBMS perspective consolidations are more efficient; but custom groups offer a lot more flexibility.

There's more...

Now we want to see all the London elements that belong to the London Area element in the same report, but we don't need such a detail for the Rest of UK element.

A very handy feature of custom groups is the ability to detail the single item that fit into a group element. Let's see how it works:

  1. After closing all reports, move to My Objects folder, and double-click on UK Areas Custom Group to edit.
  2. Right-click on the first element named London Area, from the context menu select Show Display Options.
    There's more...
  3. Click on the second option Show only the individual items within this element, and confirm with OK.
  4. Click on Save and Close.
  5. Run the 50 UK Sales with Custom Groups report, and see the results.

More Info

Subtotals in custom groups, like in consolidations, are not enabled by default. You may enable them in the Custom Group Editor from the menu Custom Group | Options:

More Info

There is a checkbox labeled Enable Subtotals Display.

Note

My personal advice with custom groups and totals is to create a new separate element, as we did in the previous recipe, in order to avoid miscalculations and/or double counting.

If, on the other hand, you plan to use subtotals with custom groups, which by the way is perfectly understandable, please read on the following exercise.

Exercise 31

Do the following:

  1. Edit the UK Areas Custom Group, right-click on London Area, and click on Show Display options.
  2. Click on the last radio button, as shown in the following screen capture:
    Exercise 31
  3. Click on Save and Close, then run the 50 UK Sales with Custom Groups report.

How much is the grand total?

Can you tell why?

Note

You can watch a screencast of this operation at:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset