MDX SUM函数和NULL值

时间:2013-05-06 22:08:17

标签: tfs2010 mdx ssas-2008

我正在尝试使用基础SQL Server 2008 Analysis Services数据库为Team Foundation Server 2010创建一些报告。多维数据集“团队系统”是TFS 2010报告附带的。

我的问题是。我尝试使用StateTehangeCount测量FactWorkItemHistory。 在某些时间段内,没有工作项状态更改,但还有其他更改。 所以我们有一些具有NULL StateChangeCount的事实行,如稍后所述。

状态更改计数度量有时会生成值0,即使基础事实行包含NULL值也是如此。此度量在[FactWorkItemHistory]上定义为SUM。[StateChangeCount]。通过设计NULLS的SUM返回0还是我错过了什么? 有问题的时期是2013-03-01(三月)和2013-05-02(五月)。

SELECT
  [DateSK],
  COUNT(*) AS COUNT,
  SUM([StateChangeCount]) AS SUM
FROM
      [Tfs_Warehouse].[dbo].[FactWorkItemHistory]
WHERE
      [WorkItemSK] IN (SELECT [WorkItemSK] FROM [Tfs_Warehouse].[dbo].[DimWorkItem]     WHERE [System_WorkItemType] = 'Bug')
GROUP BY
  [DateSK]

输出是:

DateSK                  COUNT SUM
---------------------------------------
2011-05-05 00:00:00.000 13    7
2012-03-01 00:00:00.000 2     NULL
2012-09-28 00:00:00.000 60    2
2013-05-02 00:00:00.000 16    NULL
2013-05-06 00:00:00.000 9     9

查询:

SELECT
  [DateSK],
  [StateChangeCount]
FROM
      [Tfs_Warehouse].[dbo].[FactWorkItemHistory]
WHERE
      [WorkItemSK] IN (SELECT [WorkItemSK] FROM [Tfs_Warehouse].[dbo].[DimWorkItem] WHERE [System_WorkItemType] = 'Bug')
ORDER BY   
      [DateSK]

给出:

DateSK                  StateChangeCount
---------------------------------------
2011-05-05 00:00:00.000 1
2011-05-05 00:00:00.000 NULL
2011-05-05 00:00:00.000 NULL
2011-05-05 00:00:00.000 1
2011-05-05 00:00:00.000 NULL
2011-05-05 00:00:00.000 1
2011-05-05 00:00:00.000 NULL
2011-05-05 00:00:00.000 1
2011-05-05 00:00:00.000 NULL
2011-05-05 00:00:00.000 1
2011-05-05 00:00:00.000 NULL
2011-05-05 00:00:00.000 1
2011-05-05 00:00:00.000 1
2012-03-01 00:00:00.000 NULL
2012-03-01 00:00:00.000 NULL
2012-09-28 00:00:00.000 1
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 1
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2012-09-28 00:00:00.000 NULL
2013-05-02 00:00:00.000 NULL
2013-05-02 00:00:00.000 NULL
2013-05-02 00:00:00.000 NULL
2013-05-02 00:00:00.000 NULL
2013-05-02 00:00:00.000 NULL
2013-05-02 00:00:00.000 NULL
2013-05-02 00:00:00.000 NULL
2013-05-02 00:00:00.000 NULL
2013-05-02 00:00:00.000 NULL
2013-05-02 00:00:00.000 NULL
2013-05-02 00:00:00.000 NULL
2013-05-02 00:00:00.000 NULL
2013-05-02 00:00:00.000 NULL
2013-05-02 00:00:00.000 NULL
2013-05-02 00:00:00.000 NULL
2013-05-02 00:00:00.000 NULL
2013-05-06 00:00:00.000 1
2013-05-06 00:00:00.000 1
2013-05-06 00:00:00.000 1
2013-05-06 00:00:00.000 1
2013-05-06 00:00:00.000 1
2013-05-06 00:00:00.000 1
2013-05-06 00:00:00.000 1
2013-05-06 00:00:00.000 1
2013-05-06 00:00:00.000 1

最后是MDX查询:

SELECT
 NON EMPTY { [Measures].[State Change Count] } ON COLUMNS,
NON EMPTY { ([Date].[Date].[Date].ALLMEMBERS * [Work Item].[System_State].    [System_State].ALLMEMBERS ) }
ON ROWS FROM (
            SELECT (
                  { [Work Item].[System_WorkItemType].&[Bug] }
                       )
          ON COLUMNS FROM [Team System])
            WHERE ( [Work Item].[System_WorkItemType].&[Bug] )

结果:

                              StateChangeCount
---------------------------------------------
2011-05-05  Assigned          4
2011-05-05  For verification  2
2011-05-05  In progress       1
2012-03-01  Assigned          0
2012-09-28  Assigned          2
2013-05-02  Assigned          0
2013-05-06  Assigned          9

虽然

SELECT
 NON EMPTY { [Measures].[State Change Count] } ON COLUMNS,
 NON EMPTY { ([Date].[Date].[Date].ALLMEMBERS * [Work Item].[System_State].    [System_State].ALLMEMBERS ) }
ON ROWS FROM (
        SELECT (
              { [Work Item].[System_WorkItemType].&[Bug] }
                   )
      ON COLUMNS FROM [Team System])
        WHERE ( [Work Item].[System_WorkItemType].&[Bug] )

是:

                 State Change Count
------------------------------------
May 2011          7
June 2011         (null)
July 2011         (null)
August 2011       (null)
September 2011    (null)
October 2011      (null)
November 2011     (null)
December 2011     (null)
January 2012      (null)
February 2012     (null)
March 2012        0
April 2012        (null)
May 2012          (null)
June 2012         (null)
July 2012         (null)
August 2012       (null)
September 2012    2
October 2012      (null)
November 2012     (null)
December 2012     (null)
January 2013      (null)
February 2013     (null)
March 2013        (null)
April 2013        (null)
May 2013          9
June 2013         (null)
July 2013         (null)
August 2013       (null)
Unknown           (null)

我可以看到,对于有问题的时期,有一些事实行但包含其他工作项数据更改。我希望这些项目不会污染结果,尤其是SUM。对于COUNT,同意,看到零值是好的,但不适用于SUM。

任何帮助将不胜感激。

谢谢

1 个答案:

答案 0 :(得分:1)

使用

AGGREGATE(set, measure) + 0
当我遇到编写计算成员的同样问题时,

为我工作。我没有尝试使用SUM。