BackPrevious Page Next PageNext

Using Crosstab Formulas

Crosstab formula syntax

Using crosstab formulas to apply custom aggregate functions

Managing crosstab formulas

Crosstab formula is a type of extended formula used only in crosstabs that are created using query resources. By using crosstab formulas, you can create custom aggregate functions in a crosstab to get the desired results. Crosstab formulas are private resources on the crosstab level. They cannot be used beyond its crosstab.

Crosstab formula syntax

To support more powerful and flexible calculation logic in crosstabs, crosstab formula extends the basic formula syntax in the following aspects:

Using crosstab formulas to apply custom aggregate functions

The following example shows how to apply custom aggregate function in a crosstab simply by creating a crosstab formula:

  1. Open the catalog file SampleReports.cat in <install_root>\Demo\Reports\SampleReports.
  2. Click File > New > Page Report.
  3. In the Select Component for Page Report dialog, select Crosstab and click OK. The Crosstab Wizard appears.
  4. In the Data screen, select the query WorldWideSales in Data Source 1 of the catalog.
  5. In the Display screen, add Country as the row field and Region as the column field.
  6. Click <New Crosstab Formula...> in the Crosstab Formulas node in the Resources box.

    Crosstab Wizard - Display screen

  7. In the Enter Crosstab Formula Name dialog, input CustomAggregate and click OK. The Crosstab Formula Editor is displayed.

    Crosstab Formula Editor window

  8. Define the formula as follows:
    currency ctsv1 = @(Sum(@Price));
    currency ctsv2 = @(@Country:ALL,@Region:ALL,Sum(@Price));
    if(ctsv1/ctsv2 >0.005)
    return ToText(ctsv1)
    else
    return "N/A"
  9. Save the crosstab formula and add it to the Summaries box as the aggregate field.
  10. Switch to the Style screen and select Neutral as the report style from the Style list.
  11. Click Finish to create the crosstab and preview it. The crosstab is shown somewhat as follows. You can see that in the aggregate cell, based on the formula expression, "N/A" is displayed if the price value equals to or is less than 5‰ of the grand total price $16,337.85, while the actual price is displayed if the price is more than 5‰ of the grand total price.

    Crosstab in page report

Managing crosstab formulas

You can manage the crosstab formulas of a crosstab in the Data panel as follows:

Notes:

BackPrevious Page Next PageNext