How do I make this calculated measure axis independent and portable?

时间:2016-07-11 23:08:17

标签: mdx olap mondrian

So I am a beginner at MDX and I have an MDX query that works the way I want it to so long as I put the set on either the columns or rows. If I put the same set on the filter axis it doesn't work. I'd like to make this calculated measure is independent on where this set lives. I'm guaranteed to always have some form of a set included, but I'm not guaranteed which axis the user will place it on (eg row, columns, filter).

Here is the query that works:

WITH MEMBER Measures.avgApplicants as 
   Avg([applicationDate].[yearMonth].[month].Members, [Measures].[applicants]) 
SELECT
   {[Measures].[applicants],[Measures].[avgApplicants]} ON 0,
   {[applicationDate].[yearMonth].[year].[2015]:[applicationDate].[yearMonth].[year].[2016]} ON 1
FROM [applicants]

And results:

|      | applicants | avgMonthlyApplicants |
+------+------------+----------------------+
| 2015 |        367 |                   33 |
| 2016 |        160 |                   33 |

However, if I shift this query around to move the set onto the filter axis I get nothing:

WITH MEMBER Measures.avgApplicants as 
   Avg([applicationDate].[yearMonth].[month].Members, [Measures].[applicants]) 
SELECT
   {[Measures].[applicants],[Measures].[avgApplicants]} ON 0,
   {[Gender].Members} ON 1
FROM [applicants]
WHERE ([applicationDate].[yearMonth].[year].[2015]:[applicationDate].[yearMonth].[year].[2016])

I get this:

|                           | applicants | avgApplicants |
+-------------+-------------+------------+---------------+
| All Genders |             |        478 |               |
|             | Female      |        172 |               |
|             | Male        |        183 |               |
|             | Not Known   |         61 |               |
|             | Unspecified |         62 |               |

So how do a create this calculated measure work so that it isn't dependent on which axis the set is placed on?

0 个答案:

没有答案