【问题标题】:How can i count the days within/without sales in a period我如何计算一个时期内/没有销售的天数
【发布时间】:2014-09-10 08:53:48
【问题描述】:

我如何计算一段时间内有销售/没有销售的天数。

我在下面定义了一个 MDX 查询:

SELECT { [Measures].[Sales], [Measures].[Amount] } ON COLUMNS
NONEMPTY({ [Dim Customer].[Customer ID].[Customer ID].ALLMEMBERS * 
           [Time].[Month].CHILDREN
}) DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME ON ROWS
FROM [MyCube]

结果显示每个客户和月份的客户在相应月份的销售额和金额。

CustomID / Month / Sales / Amount:
1 / 2013 01 / 123 / 2234:
1 / 2013 02 / 2 / 95:
1 / 2013 03 / 212 / 11111:
2 / 2013 01 / 122 / 2121:
2 / 2013 02 / 231 / 3333:

现在我需要一个计数器/列来显示当月没有销售的天数。

CustomID / Month / Sales / Amount / DaysNoSale:
1 / 2013 01 / 123 / 2234 / 3:
1 / 2013 02 / 2 / 95 / 26:
1 / 2013 03 / 212 / 11111 / 0:
2 / 2013 01 / 122 / 2121 / 0:
2 / 2013 02 / 231 / 3333 / 0:

在多维数据集中,我们有每天的详细信息,因此可以显示每天的销售数量。 在没有销售的日子里,这个数字是 0。

有谁知道我如何解决这个问题。
谢谢转发

【问题讨论】:

    标签: mdx


    【解决方案1】:

    假设您的 Day 属性名为 [Time].[Day],您将使用:

    WITH Member Measures.[Days No Sale] AS
         Filter([Time].[Day].[Day].Members * { [Time].[Month].CurrentMember },
                ([Measures].[Sales], [Dim Customer].[Customer ID].CurrentMember) = 0
               ).Count
    SELECT { [Measures].[Sales], [Measures].[Amount], Measures.[Days No Sale] }
           ON COLUMNS,
           NONEMPTY({ [Dim Customer].[Customer ID].[Customer ID].ALLMEMBERS * 
                    [Time].[Month].CHILDREN
                   })
           DIMENSION PROPERTIES MEMBER_CAPTION, MEMBER_UNIQUE_NAME
           ON ROWS
      FROM [MyCube]
    

    [Time].[Day].[Day].Members * { [Time].[Month].CurrentMember } 是多维数据集中所有天数与行的当前月份的叉积。并且由于 Analysis Services Autoexists 功能,这只会返回非空元组,即。 e.一个月中的每一天一个元组,如 e。 G。在日期列中包含 2014 年 9 月 10 日和月列中包含 2013 年 7 月的时间维度表中没有记录。 IE。维度内的叉积在 Analysis Services 中并不是真正的叉积。

    然后Filter 方法将这些限制为当前客户ID 没有销售的那些,最后Count 只计算这些。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-29
      • 1970-01-01
      相关资源
      最近更新 更多