BackPrevious Page Next PageNext

Using Crosstab Formulas

Crosstab formula syntax

Using crosstab formulas to apply custom aggregate functions

Managing crosstab formulas

Crosstab formulas are a type of extended formulas 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 by creating a crosstab formula:

  1. Make sure SampleReports.cat is the currently open catalog file. If not click File > Open Catalog to open it from <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.
  4. In the Data screen of the Crosstab Wizard, 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.

    Add Fields to the Crosstab

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

    Create a Crosstab Formula

  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. You can find the aggregate function of the aggregate field is displayed as Custom and cannot be edited.
  10. Switch to the Style screen and select Classic as the report style from the Style box.
  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 Result with Custom Aggregate Funtion

Managing crosstab formulas

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

Notes:

BackPrevious Page Next PageNext