【问题标题】:How to use IsLeaf in mondrian mdx formula?如何在蒙德里安 mdx 公式中使用 IsLeaf?
【发布时间】:2017-03-07 10:44:21
【问题描述】:

试图在 Pentaho Mondrian Cube 中重新创建这个公式。

iif(ISLEAF([Time].[Month].CurrentMember)),[Measures].m1,0)

这个公式已经在 SSAS 多维数据集中使用。需要在 Pentaho Mondrian Cube 中重新创建类似的公式。

IsLeaf 可以在 mondrian 中使用还是有其他替代方法?

【问题讨论】:

  • 我不知道 SSAS。但你的要求是什么?如果您想要类似示例:假设我想要所有男性的总和,那么我将如何正确的是:此分类中的 SUM( [categorized].[MALE] , [Measures].[GENDER] ) 是我的维度名称。
  • @WorkingHard.. 感谢您的输入.. 我的要求是找到维度 Month 的最后一个节点的度量 m1 的值.. 例如,将有 12 个月的选择.. 所以在报告的最后一行应该显示上个月的 m1 的值(在这种情况下是第 12 个月).. 我该如何在 Pentaho 中做到这一点?
  • [Dim Month.columnname].[1]试试这个,如果它工作与否。
  • @Akira:现在很难理解为什么需要 IsLeaf 函数。您能否添加更多信息:最后一个节点到底是什么意思:[Month] 级别中的最后一个现有节点或层次结构中最远的节点?您想将表达式用作多维数据集中的计算度量,还是仅在一个特定查询中使用它?如果是后者,那么很高兴知道您的查询和 [Time] 层次结构的级别。无论如何,很高兴看到预期的输出。
  • @user4637357 感谢您的输入..我们正在使用计算度量中的表达式..详细说明,考虑计算一个月的收盘库存..我们希望仅显示此值一次结果集中的最后一行而不是显示报告的每一行..所以我们需要访问结果集中的最后一行..如果是最后一行,则显示该值,否则将其设置为零..我们怎么能这样做?

标签: function mdx pentaho cube mondrian


【解决方案1】:

类似下面的内容应该可以在默认层次结构中的任意级别上工作。

如果您选择[Time].[Year] 成员,它将返回去年的 [Mesures].m1,它(具有非空 m1 度量并满足您的过滤条件)。

或者它会返回去年最后一个月的度量,如果你选择[Time].[Month]成员,它有非空的m1度量。

虽然我认为如果你混合不同级别的成员(例如WITH SET time_members AS {[Time].[2017], [Time].[2017].[1]. [Time].[2017].[1].[31]})会起作用

如果您不需要这种通用的方法,那么这个解决方案可能会被简化,并且可能会提高度量计算速度。

警告:查询可能会导致 100% 的 CPU 利用率(或者可能不会,我不确定),从而使您的服务器无响应。因此,请谨慎选择您的测试环境。

免责声明:我暂时没有mondrian可以测试,所以下面的例子很可能有错误。

Iif(
    // Check if current [Time] member is the last member:
    [Time].CurrentMember
    IS
    // Take the 0th member from the end of the set (AFAIK, mondrian sets are guaranteed to be ordered):
    Tail(
        // AFAIK, Level.Members returns the full set of members, disregarding query filters.
        // So I use Filter function to filter members, which don't exist in context of current cell.
        // It should leave only members, which (are related to current cell and satisfy filter conditions of the query).
        Filter(
            [Time].CurrentMember.Level.members
            // If your measure is nullable, then you might want to use count measure in this condition instead of m1:
            , NOT IsEmpty([Measures].m1)
        )
        // Number of members to get by the Tail() function:
        , 1
        // Return the only member of the set as a Member (not as a Set):
    ).Item(0)
    // return if true
    , [Measures].m1
    // else:
    , 0
)

一些可能有问题需要测试的点:

  1. 如果最后一个 [Time] 成员为空 m1,如何计算度量 衡量(如果这是您衡量的有效案例)

  2. 如何在不同的 [时间] 级别计算度量值 层次结构。

  3. 如果不使用 [Time] 维度,如何计算度量 明确报告。

  4. 如果在切片器上使用 [时间] 维度,如何计算度量 仅轴(在 WHERE 条件下)

  5. 如果您使用 [时间] 的受限集,如何计算度量 成员,例如显式枚举集合文字中的成员(例如 {[Time].[2006].[01], [Time].[2006].[02]}) 或通过使用 Filter() 维度上的函数。

  6. 如果您在其他设备上使用过滤器,如何计算度量 尺寸/度量。

  7. 如何在 [Time] 的计算成员处计算度量 维度(包括分析器生成的总计和小计)。

  8. 如果您选择不同的成员,如何计算度量 同一轴上的水平。

【讨论】:

  • 您能否查看以下查询?当我在 Pentaho 聚合设计器中创建一个名为 AggTable1 的聚合表时,会生成此查询。 select Dim_Time.Time_Id as c0, Dim_Time.month_no as c1 from Dim_Time as Dim_Time where Dim_Time.Time_Id = @9876 Dim_Time.Time_Id, Dim_Time.month_no order by ISNULL(Dim_Time.Time_Id) ASC, Dim_Time.Time_Id ASC 为什么在 from 子句中没有选择 AggTable1 表?跨度>
  • 抱歉,对聚合表没有太多经验。我唯一可以建议的是检查是否存在具有相同别名的不同表 - 在这种情况下,其中一个表不会出现在 from 子句中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2016-11-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-08-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多