如何使用MDX执行不同的求和?
所以我有这样的数据:如何使用MDX执行不同的求和?,mdx,mondrian,Mdx,Mondrian,所以我有这样的数据: 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 ...
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
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])
我想对员工总数进行汇总,但我需要删除员工id汇总中的重复条目。从数据中可以看到,员工id 1在表中多次出现,但我只想添加其“员工总数”列一次。例如,如果我在某一年进行汇总,我可能会使用以下查询得到一份报告:
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做到这一点?有没有办法控制每个员工的总和中使用哪一行?您可以使用如下表达式:
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
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))
这不是employee_id列的简单不同计数聚合吗?我想对每个唯一员工id的“编制”字段中的值求和,忽略重复条目。我不明白这到底是怎么做到的。还请记住,上一年的滚动只是一个例子。我希望我计算出来的度量值不包含我要计算的维度,这样我就可以在我创建的任何查询中使用它。你能更好地解释一下吗?如果这真的是一个解决方案,我想奖励你一笔赏金。但是,第一个建议似乎没有什么不同,那就是一个不同的计数。你能解释一下为什么这两种方法都有效吗?