PTR logo

Blog Post

SQL Server MDX - Working With More Than Two Axes

SQL Server MDX - Working With More Than Two Axes
MD

Author

Mandy Doward

Date

October 4, 2016

Length

2 mins

Working With Axes in MDX SELECT Statements

The SQL Server MDX SELECT statement supports the specification of up to 128 axes, but we generally only use two in our queries.

  • The MDX query editor in Management Studio can only represent two axes, columns and rows.

  • SSRS only supports two axes in MDX SELECT statements.

Specialist client tools might require data to be delivered via more than two axes, but in the main two axes is plenty for our requirements.

There is, however, a scenario where using more than two axes can be helpful in an MDX SELECT statement.

Making MDX Filtering Easier

An MDX SELECT statement restricts a hierarchy from appearing in more than one part of the statement.

  • A hierarchy can appear in a single axis or in a WHERE clause (on a slicer).

In the main this is not an issue, but occasionally it results in us having to use attribiute hierarchies in addition to user defined hierarchies to achieve the level of filtering we require.

Using a multiple axis query as a subquery to an MDX SELECT statement can overcome this.

Take the following example:

The sub query cannot be run individually in Management Studio as it references 3 axes (0, 1 and 2), but we can see that it slices the cube by Calendar Year 2007, Country Canada and Product Category Bikes, so that is the only part of the cube that will be passed to the outer SELECT statement.

The following query uses two axes to demonstrate the slicing that those tuples result in:

The result is:

The outer MDX query then specifies all sales territories, product categories and months:

and the WHERE clause in the outer query limits the results to the Internet Sales Amount measure:

The result of the whole MDX SELECT statement is shown below:

We can see that only Bikes, Canada and months from 2007 are included in the final results.

If you would like to learn more about MDX SELECT statements and querying cubes why not think about attending one of our MDX Programming training courses?

Share This Page

MD

Mandy Doward

Managing Director

PTR’s owner and Managing Director is a Microsoft MCSE certified Business Intelligence (BI) Consultant, with over 30 years of experience working with data analytics and BI.

Latest Articles

PTR FAQs

See our FAQs or get in contact for more information on any of our services, solutions, or to start your PTR journey.

Ready to take your business to the next level?

Reach out to our team of experts and learn more about our consultancy and training services.