Filtering hierarchies in MDX WITH clause

好久不见. 提交于 2019-12-11 16:08:43

问题


By using the answer of MDX on multiple hierarchical dimensions I have the following MDX query:

with
member L1Y1 as ([Dim Location].[Hierarchy].[Center].&[1],
        [Dim Date].[Calendar Date].[Year].&[2010],
        [Measures].[x])                 
select ([Dim Attribute].[Parent Code].&[10000]) on 0, 
       ({L1Y1}) on 1
from DS

Now the problem is how to filter the L1Y1 based on its children. For example suppose we want to filter it so that only season 2 and month 7 included in the query. The following query output is the same as above and the where clause has no effect:

with
member L1Y1 as ([Dim Location].[Hierarchy].[Center].&[1],
        [Dim Date].[Calendar Date].[Year].&[2010],
        [Measures].[x])                 
select ([Dim Attribute].[Parent Code].&[10000]) on 0, 
       ({L1Y1}) on 1
from DS
where [Dim Date].[Calendar Date].[Season].&[2] and 
      [Dim Date].[Calendar Date].[Month].&[7]

回答1:


How about:

with
member L1Y1 as ([Dim Location].[Hierarchy].[Center].&[1],
        [Dim Date].[Calendar Date].[Year].&[2010],
        [Measures].[x])
member S2 as ([Dim Location].[Hierarchy].[Center].&[1],
        [Dim Date].[Calendar Date].[Season].&[2],
        [Measures].[x])
member M7 as ([Dim Location].[Hierarchy].[Center].&[1],
        [Dim Date].[Calendar Date].[Month].&[7],
        [Measures].[x])     
select ([Dim Attribute].[Parent Code].&[10000]) on 0, 
       (L1Y1, S2, M7) on 1
from DS

I understand it is a somewhat more laborous approach, but you would get the result. If you otherwise want to get a single value only you can try keeping only the M7 measure.




回答2:


Unless you removed the attributes you should have multiple hierarchies available in your time dimension. Can you try this :

with
member L1Y1 as ([Dim Location].[Hierarchy].[Center].&[1],
    [Dim Date].[Calendar Date].[Year].&[2010],
    [Measures].[x])                 
select ([Dim Attribute].[Parent Code].&[10000]) on 0, 
   ({L1Y1}) on 1
from DS
where [Dim Date].[Season].&[2] and [Dim Date].[Month].&[7]

Note, as we are not using the hierarchy [Calendar Date] time member is not overwritten but filtered.



来源:https://stackoverflow.com/questions/6278462/filtering-hierarchies-in-mdx-with-clause

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!