我在矩阵中创建了一个非常简单的员工层次结构,如下所示:
Buildings
-------------------------------------------------
Employee | One | Two | R2D2 | Three |
----------------------------------------------------------------------
Miss Piggy | 15 | | | |
Walter Muppet | | 50 | | |
80's robot | | | 2 | |
Andy Pig | | | | 2 |
Randy Pig | | | | 1 |
Animal Muppet | 15 | 50 | 3 | |
...
...
SQL是recursive cte,返回:EmployeeName,ReportsToID,GroupLevel,Building,EmployeeID。在矩阵中,我有一个带有these设置的employee列来创建层次结构分组。为了通过在矩阵中构建来获得员工的数量,我有这样的表达式:
=IIF(Fields!GroupLevel.Value="0",
IIF(InScope("Building"),
IIF(InScope("EmployeeName"),sum(Fields!Count.Value, "Building", Recursive),""),""),
IIF(Fields!GroupLevel.Value,Sum(Fields!Count.Value, "EmployeeName", recursive),""))
依此类推,你可以扩展层次结构,直到没有更多的经理人为止。计数是相应建筑物中所有直接和间接报告的总和。等。
我想要的是让每位经理在所有建筑物中拥有所有员工的总数。 我可以添加行/列总数来获得Miss Piggy的总和,但是我也想要其他经理的所有建筑物的总数。意思是Piggy小姐有人坐在建筑物内:两个,R2D2和三个。动物布偶有人坐在建筑物中:一,二,三。
理想情况下,我希望报告看起来像这样。
Buildings
-------------------------------------------------
Employee | One | Two | R2D2 | Three |
----------------------------------------------------------------------
Miss Piggy | 15 | 100 | 5 | 6 |
Walter Muppet | | 50 | | |
80's robot | | | 2 | |
Andy Pig | | | | 2 |
Randy Pig | | | | 1 |
Animal Muppet | 15 | 50 | | 3 |
... | | | | 2 |
... | | | 1 | |
任何想法如何完成?