1
votes

I have a seemingly simple requirement to create a query of price data that will return four sets of price data for different dates:

  1. The lowest date of the range
  2. The highest date of the range
  3. The aggregate sum for the entire range

The closest I have is the following query:

WITH set [Range] as {[Effective Date].[Date].&[2015-12-01T00:00:00] : [Effective Date].[Date].&[2015-12-31T00:00:00]}
select
NON EMPTY{
    filter([Effective Date].[Date].&[2015-12-01T00:00:00], [Measures].[Plan Price]),
    filter([Effective Date].[Date].&[2015-12-31T00:00:00], [Measures].[Plan Price]),
    nonempty([Measures].[Money In], [Range]),
    nonempty([Measures].[Money Out], [Range])
} on 0,
NON EMPTY{
[Region Manager].[Full Name].[Full Name]
} on 1
from [Cube]

However, the date ranges as such return the error:

Two sets specified in the function have different dimensionality.

The "filter" or "nonempty" statements will work individually but I cannot get them to work in a single query. How can I do this? Will it be helpful to use a sub query?

2
you're trying to make a set of tuples - which is fine. Each tuple needs to have the same "dimensionality". This means it needs to be this stucture {([A],[B],[C]...),([A],[B],[C]...),([A],[B],[C]...) ...} where A, B and C need to be the same hierarchies, in the same order.whytheq

2 Answers

1
votes

Try this:

WITH 
  SET [Range] AS 
    {
      [Effective Date].[Date].&[2015-12-01T00:00:00] 
    : [Effective Date].[Date].&[2015-12-31T00:00:00]
    }
SELECT
NON EMPTY
    {
      ([Effective Date].[Date].&[2015-12-01T00:00:00], [Measures].[Plan Price])
     ,([Effective Date].[Date].&[2015-12-31T00:00:00], [Measures].[Plan Price])
     ,{nonempty([Range]*[Measures].[Money In])}
     ,{nonempty([Range]*[Measures].[Money Out])}
    }
ON 0,
NON EMPTY [Region Manager].[Full Name].[Full Name] ON 1
FROM [Cube];

But NonEmpty is not really required so this is more concise:

WITH 
  SET [Range] AS 
    {
      [Effective Date].[Date].&[2015-12-01T00:00:00] 
    : [Effective Date].[Date].&[2015-12-31T00:00:00]
    }
SELECT
NON EMPTY
    {
      ([Effective Date].[Date].&[2015-12-01T00:00:00], [Measures].[Plan Price])
     ,([Effective Date].[Date].&[2015-12-31T00:00:00], [Measures].[Plan Price])
     ,{[Range]*[Measures].[Money In]}
     ,{[Range]*[Measures].[Money Out]}
    }
ON 0,
NON EMPTY [Region Manager].[Full Name].[Full Name] ON 1
FROM [Cube];

To aggregate you need a new custom measure:

WITH 
  SET [Range] AS 
    {
      [Effective Date].[Date].&[2015-12-01T00:00:00] 
    : [Effective Date].[Date].&[2015-12-31T00:00:00]
    }
  MEMBER [Effective Date].[Date].[All].[AggRange] AS 
    Aggregate([Range])
SELECT
NON EMPTY
    {
      ([Effective Date].[Date].&[2015-12-01T00:00:00], [Measures].[Plan Price])
     ,([Effective Date].[Date].&[2015-12-31T00:00:00], [Measures].[Plan Price])
     ,([Effective Date].[Date].[All].[AggRange],[Measures].[Money In])
     ,([Effective Date].[Date].[All].[AggRange],[Measures].[Money Out])
    }
ON 0,
NON EMPTY [Region Manager].[Full Name].[Full Name] ON 1
FROM [Cube];
1
votes

Unless you're using a dialect of MDX I've never seen, there's no need to use double braces ({{....}}).

Braces mean that the contents are a set. Inside braces, the comma (,) is a UNION operator:

{Tom,Dick,Harry}

gives a set of three people.

Because you're using braces here:

non empty{{
    filter([Effective Date].[Date].&[2015-12-01T00:00:00], [Measures].[Plan Price]),
    filter([Effective Date].[Date].&[2015-12-31T00:00:00], [Measures].[Plan Price]),
    nonempty([Measures].[Money In], [Range]),
    nonempty([Measures].[Money Out], [Range])
}}

the parser is trying to form a set out of two members of the Effective Date dimension, and two members of the Measure dimension. This is impossible, because they have different dimensionality.

It would have been nice if the parser had told you that the

function

it refers to is the UNION (,) function within a set definition. That's the MDX parser for you...

If you want to show the two measures and two dates on the same axis, define the two dates as calculated measures (WITH MEMBER Measures.Bla AS Head([Range],1), for example).