2

所以我有这样的数据:

Date       EMPLOYEE_ID   HEADCOUNT   TERMINATIONS
1/31/2011        1            1             0 
2/28/2011        1            1             0
3/31/2011        1            1             0
4/30/2011        1            1             0
...
1/31/2012        1            1             0
2/28/2012        1            1             0
3/31/2012        1            1             0

1/31/2012        2            1             0
2/28/2011        2            1             0
3/31/2011        2            1             0
4/30/2011        2            0             1    

1/31/2012        3            1             0
2/28/2011        3            1             0
3/31/2011        3            1             0
4/30/2011        3            1             0
...
1/31/2012        3            1             0
2/28/2012        3            1             0
3/31/2012        3            1             0

我想总结员工人数,但我需要从employee_id 的总和中删除重复的条目。从数据中可以看到employee_id 1 在表中出现了很多次,但我只想添加它的headcount 列一次。例如,如果我上一年汇总,我可能会使用以下查询获得一份报告:

with member [Measures].[Distinct HeadCount] as
          ??? how do I define this???
select { [Date].[YEAR].children } on ROWS, 
       { [Measures].[Distinct HeadCount] } on COLUMNS 
       from [someCube]

它会产生这个输出:

YEAR    Distinct HeadCount
2011           3
2012           2

任何想法如何用 MDX 做到这一点?有没有办法控制每个员工的总和中使用哪一行?

4

1 回答 1

1

您可以使用这样的表达式:

WITH MEMBER [Measures].[Distinct HeadCount] AS
    Sum(NonEmpty('the set of the employee ids', 'all the dates of the current year (ie [Date].[YEAR].CurrentMember)'), [Measures].[HeadCount])

如果你想要一个更通用的表达式,你可以使用这个:

WITH MEMBER [Measures].[Distinct HeadCount] AS
    Sum(NonEmpty('the set of the employee ids', 
                 Descendants(Axis(0).Item(0).Item(0).Hierarchy.CurrentMember, Axis(0).Item(0).Item(0).Hierarchy.CurrentMember.Level, LEAVES)),
        IIf(IsLeaf(Axis(0).Item(0).Item(0).Hierarchy.CurrentMember),
            [Measures].[HeadCount],
            NULL))
于 2012-10-24T21:33:23.547 回答