创建自定义MDX命名集

时间:2014-02-12 22:49:47

标签: ssas mdx

我有两个维度[Session Length][Date],以及我的多维数据集中名为[Count - Logins]的度量。 [Session Length]维度包含一个名为[Session Length]的属性,其成员是从0240的整数。

我喜欢编写一个MDX查询,该查询会将[Count - Logins]聚合在[Session Length]维度的自定义子集上(即我想根据[Session Length]维度创建自定义集合并聚合统计此自定义集的各个成员)。这是我到目前为止提出的查询,但不幸的是我不知道如何前进:

WITH SET [Description] AS {
         [SessionLength].[Session Length].&[0], //Glimpse
         [SessionLength].[Session Length].&[1]:[SessionLength].[Session Length].&[5], //Short
         [SessionLength].[Session Length].&[6]:[SessionLength].[Session Length].&[30], //Medium
         [SessionLength].[Session Length].&[31]:[SessionLength].[Session Length].&[90], //Long
         [SessionLength].[Session Length].&[90]:[SessionLength].[Session Length].&[240]} //Extended
     MEMBER [SessionLength].[Session Length].SessionDescription AS
            Aggregate([Description])
     SELECT
     { [Measures].[Count - Logins] }
     ON COLUMNS,
    NONEMPTY({[SessionLength].[Session Length].SessionDescription} * {[Date].[Date].[Date]}) ON ROWS
FROM MyCube

使用以下示例结果集:

    Session Length   |    Date    | Count - Logins
   -------------------------------------------------
  SessionDescription | 2014-02-01 | 22
  SessionDescription | 2014-02-01 | 17

正如您所看到的那样,计数正在整个集合中聚合而不是每个成员单独聚合。这是我希望产生的结果:

    Session Length   |    Date    | Count - Logins
   -------------------------------------------------
  Glimpse            | 2014-02-01 | 3
  Short              | 2014-02-01 | 4
  Medium             | 2014-02-01 | 9
  Long               | 2014-02-01 | 5
  Extended           | 2014-02-01 | 1
  Glimpse            | 2014-02-02 | 2
  Short              | 2014-02-02 | 5
  Medium             | 2014-02-02 | 7
  Long               | 2014-02-02 | 2
  Extended           | 2014-02-02 | 1

任何帮助将不胜感激。我知道这可以通过修改DSV来实现,但我不想改变Cube的结构。

1 个答案:

答案 0 :(得分:4)

如果要在行e上查看单独的条目,则必须创建单独的SessionDescription成员。 G。像这样:

WITH
     MEMBER [SessionLength].[Session Length].Glimpse AS
            Aggregate([SessionLength].[Session Length].&[0])
     MEMBER [SessionLength].[Session Length].Short AS
            Aggregate([SessionLength].[Session Length].&[1]:[SessionLength].[Session Length].&[5])
     MEMBER [SessionLength].[Session Length].Medium AS
            Aggregate([SessionLength].[Session Length].&[6]:[SessionLength].[Session Length].&[30])
     MEMBER [SessionLength].[Session Length].Long AS
            Aggregate([SessionLength].[Session Length].&[31]:[SessionLength].[Session Length].&[90])
     MEMBER [SessionLength].[Session Length].Extended AS
            Aggregate([SessionLength].[Session Length].&[90]:[SessionLength].[Session Length].&[240])
     SELECT
     { [Measures].[Count - Logins] }
     ON COLUMNS,
    NONEMPTY({
             [SessionLength].[Session Length].Glimpse,
             [SessionLength].[Session Length].Short,
             [SessionLength].[Session Length].Medium,
             [SessionLength].[Session Length].Long,
             [SessionLength].[Session Length].Extended
             }
             * {[Date].[Date].[Date]})
    ON ROWS
FROM MyCube

顺便说一句,我将90成员留在原始查询中的LongExtended中。如果您不想对这些进行重复计算,则应将其从一个中删除。