3

Useless Use of Crossjoin

 3 years ago
source link: https://www.cubecoder.com/useless-use-of-crossjoin/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Useless Use of Crossjoin

February 24, 2016February 25, 2016 by TimG
Even fans of MDX like me will agree that it isn’t the most aesthetically pleasing language, so it’s painful to see it made more convoluted than strictly necessary. This post is a grumble about a piece of redundant syntax that appears far too often, and has really begun to grate…

A quick definition of terms. A tuple represents an intersection or slice of a cube, specified by a list of members. The list of members does not need to include all dimensions, but any dimension included must be represented by only one member.

In MDX, parentheses are used to denote a tuple. Sometimes this is optional, but I prefer to include them. The following are examples of valid tuples (from Sample.Basic):

([Jan])
([Jan], [Sales])
([Jan], [Sales], [New York])

A set is a collection of tuples sharing the same dimensionality. In MDX, braces are used to denote a set. Again, this is sometimes optional, but recommended for clarity. The following are examples of valid sets:

{([Jan]), ([Feb])}
{([Jan], [Sales]), ([Feb], [Sales])}

A Crossjoin is used to generate a set which is the “cross-product” of sets from more than one dimension. For example, if we want to reference all Sales and Expenses from January and February, we can use a Crossjoin like this:

Crossjoin({[Jan], [Feb]}, {[Sales], [Expenses]})

It produces the following set:

{([Jan], [Sales]), ([Feb], [Sales]), ([Jan], [Expenses]), ([Feb], [Expenses])}

But here’s the deal:

  1. Though a Crossjoin can be used to construct a tuple, we only need it to construct a set.
  2. We don’t need to nest Crossjoins for every dimension in the set, only those from which we are choosing more than one member. All other dimensions can be represented by a single tuple.

For example, if we want to reference January Sales (from Sample.Basic), do this…

([Jan], [Sales])

…not this…

Crossjoin({[Jan]}, {[Sales]})

And if, we want to reference January and February Sales for Actuals only, do this…

Crossjoin({[Jan], [Feb]}, ([Sales], [Actuals]))

…not this…

Crossjoin({[Jan], [Feb]}, {Crossjoin({[Sales]}, {[Actuals]})})

I hope these examples show the principle, though they probably don’t convey the full horror of encountering a dozen nested Crossjoins used to construct what is actually a simple tuple.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK