【问题标题】:Filtering hierarchies in MDX WITH clause在 MDX WITH 子句中过滤层次结构
【发布时间】:2017-09-06 00:23:11
【问题描述】:

通过使用MDX on multiple hierarchical dimensions 的答案,我有以下 MDX 查询:

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

现在的问题是如何根据其子级过滤 L1Y1。例如,假设我们想要过滤它,以便查询中只包含第 2 季和第 7 个月。以下查询输出同上,where子句无效:

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]

【问题讨论】:

    标签: ssas mdx olap


    【解决方案1】:

    除非您删除了属性,否则您的时间维度中应该有多个可用的层次结构。你可以试试这个:

    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]
    

    注意,由于我们使用层次结构[日历日期]时间成员不会被覆盖而是被过滤。

    【讨论】:

    • 但是当where子句的维度不一样的时候就不行了。
    • 在你的例子中,所有的都是 [Dim Date] 的层次结构,不是吗?...如果不是,你是对的
    • 从 SSAS 观点来看(!) [Dim Date].[Season] 和 [Dim Data].[Month] 是 [Dim Data] 维度的不同层次结构。
    • 如果它们是相同维度的层次结构,它应该可以工作,不是吗?
    • 你让我的生活变得艰难 :-),你可以在过滤器中使用一个集合而不是单个元组: where { ([Dim Date].[Season].&[2], [Dim Date].[Month].[All Member]) + ([Dim Date].[Season].[All Member],[Dim Date].[Month].&[7]) }
    【解决方案2】:

    怎么样:

    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
    

    我知道这是一种更费力的方法,但您会得到结果。如果您只想获得单个值,则可以尝试仅保留 M7 度量。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-30
    • 2014-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-03
    相关资源
    最近更新 更多