【问题标题】:How To Have Running Total Based on Filtered Date in MDX?如何在 MDX 中根据过滤日期运行总计?
【发布时间】:2023-03-21 22:36:02
【问题描述】:

我需要有计算成员来计算基于 Dim Date 的运行总数 这应该适用于报告中过滤的所有日期。 大多数解决方案从 Dim Date 或 Null 中的第一个日期计算到当前成员,但我需要从过滤到当前成员的第一个日期计算并排除它们不在过滤器中的日期

【问题讨论】:

    标签: ssas mdx cumulative-sum


    【解决方案1】:

    试试这个:

    //capture the dates selected in the where clause of the query
    CREATE DYNAMIC SET CURRENTCUBE.SelectedDates as
    [Dim Date].[Date].[Date].Members;
    
    CREATE MEMBER CURRENTCUBE.[Measures].[Cumulative Sale Price] as
    Sum(
     {
      SelectedDates.Item(0).Item(0)
      :
      Tail(Existing [Dim Date].[Date].[Date].Members, 1).Item(0).Item(0) //capture the last date present in the Filter context for this cell
     },
     [Measures].[Sale Price]
    );
    
    CREATE MEMBER CURRENTCUBE.[Measures].[Cumulative Sale Price with Skips] as
    Sum(
     Exists(
      SelectedDates,
      {
       SelectedDates.Item(0).Item(0)
       :
       Tail(Existing [Dim Date].[Date].[Date].Members, 1).Item(0).Item(0) //capture the last date present in the Filter context for this cell
      }
     ),
     [Measures].[Sale Price]
    );
    

    【讨论】:

    • 非常感谢您的回答,这对我很有帮助,但是如果我们排除第一个成员和当前成员之间的某些日期,那么我们间隔中不存在的日期呢?我们的计算例如,如果第一个成员是 2017-01,当前成员是 2019-10,如果我们仅过滤 2017 和 2019 的 Dim Date,则 2018 的所有价格也将汇总
    • 我们可以在 mdx 中有递归求和吗?如果我们可以将每个成员与上一个成员相加,也许我们可以解决这个问题,你知道如何在 mdx 中进行递归聚合吗?
    • @sepideh.sp 我在我的答案中添加了第二个度量。看看它是否像你想要的那样处理跳过的日期。
    • 非常感谢您的帮助,成功了 :)
    • 我在 DimDate 中使用日期时遇到性能问题,在 YearMonth 中可以,但是当我们详细到 Day 时,它加载至少 10 秒,我们可以做一些工作来提高性能吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多