Schema Workbench - Testing MDX Query

This guide is based on FoodMart data source, a MySQL database example provided when installing JasperReports Server. The purpose is to get familiar with MDX syntax.

  1. Launch Jaspersoft OLAP Schema Workbench and open the OLAP schema created from the previous guide Creating an OLAP Schema.
  2. Click on MDX Query icon.

    Figure 1

Measures and Dimension

  1. Try this basic MDX query:

    SELECT {
      [Measures].[product NUMBER],
      [Measures].[class NUMBER]
    } ON COLUMNS,
    {
      [Product]
    } ON ROWS
    FROM Products

    [product number] and [class number] are measures.
    [Product] is a dimension.
    Products is a cube.

  2. Click on Execute to display the result:

    Figure 2


ON ROWS - ON COLUMNS

Previously, measures were set as COLUMNS and Product dimension set as ROWS. But it can be switched: measures set as ROWS and Product Dimension set as COLUMNS.

  1. Try switching ON COLUMNS and ON ROWS. Do Execute to display the result:

    Figure 3

Dimension's Methods

[dimension].children

SELECT {
    [Measures].[product NUMBER],
    [Measures].[class NUMBER]
} ON COLUMNS,
{
    [Product].children
} ON ROWS FROM Products

Figure 4

[dimension].firstChild or .lastChild

SELECT {
    [Measures].[product NUMBER],
    [Measures].[class NUMBER]
} ON COLUMNS, {
    [Product].firstChild // OR [Product].lastChild
} ON ROWS FROM Products

Figure 5
Figure 6

Drilling Dimension

Reminder: the Product dimension's hierarchy is Product > Brand > Name > SKU.

You can drill a dimension to focus the display on particular values. You just have to know your Brand, Name or SKU value.

SELECT {
    [Measures].[product NUMBER],
    [Measures].[class NUMBER]
} ON COLUMNS, {
    [Product],
    [Product].[Tri-State].[Tri-State Dried Mushrooms],
    [Product].[Big City],
    [Product].Queen.children
} ON ROWS FROM Products

Figure 7

Generating default MDX queries

Since the new Jaspersoft OLAP Schema Workbench 3.5.4 released, you have a new button to generate MDX queries.

  • Click on MDX Query icon. Now just beside of Save As icon, click on Generate MDX Queries icon. Here is below a generated query:

    SELECT [Measures].AllMembers ON COLUMNS,
           Hierarchize([Product].[ALL Products].Children) ON ROWS
      FROM [Products];

Figure 8

Notes

Square brackets

  • If your OLAP schema contains items named with special characters such as space in "Big City", you have to use square brackets [ ]. Example: [Big City].
  • If not, [ ] are not necessary. Example: Queen or [Queen].

See also...

Feedback
randomness