如何在 SSRS 报表生成器中分组并循环遍历子组值

How to group by and loop through sub-group values in SSRS report builder

我正在将 SSRS 报表生成器与 SharePoint 列表一起使用。我在报表生成器中创建了一个矩阵,该矩阵按 组织 站点评估状态 进行分组。我希望能够根据属于该组织的站点的整体评估状态来设置包含组织名称的单元格的背景颜色。

我的站点评估状态值为 "not started"、"in progress"、"complete"。如果组织的任何站点的状态为 "not started",则组织单元格的背景颜色为红色。只要该组织的所有站点的状态都是 "in progress",那么该组织的背景单元格就是黄色的。最后,只要所有组织站点的值为 "complete",那么组织背景颜色为绿色。

Excel中的示例

我知道如何使用表达式调用代码来更改单元格的背景颜色,但不确定如何传递我需要的值或循环遍历这些值。我想我必须在自定义代码部分的 VB 中写一些东西,但不确定如何使用 Report Builder

在组内循环

尝试在组织的背景颜色 属性 中使用此表达式:

=Switch(
Array.IndexOf(LookupSet(Fields!Organization.Value,Fields!Organization.Value,Fields!Status.Value,"DataSet2"),"Not Started")>-1,"Red",
Array.IndexOf(LookupSet(Fields!Organization.Value,Fields!Organization.Value,Fields!Status.Value,"DataSet2"),"In Progress")>-1,"Yellow",
Array.IndexOf(LookupSet(Fields!Organization.Value,Fields!Organization.Value,Fields!Status.Value,"DataSet2"),"Complete")>-1,"Green"
)

它产生这个:

更新 1:

Switch 函数计算每个案例:

  1. 状态列包含 Not Started 个值
  2. 状态列包含 In Progress 个值。
  3. 状态列包含 Complete 个值)。

为了检查 Status 列中是否有 Not Started 值,我使用了 IndexOf() and LookupSet() 函数。 LookupSet 将给我一个包含每个组织状态的数组,因此使用 IndexOf 我搜索未开始、进行中或完成值。如果找到一个值,它 returns 它存储在数组中的索引,否则它 returns -1.

更新 2: 基于用户评论的版本。

首先你要了解Switch函数在SSRS中是如何工作的。事实上,它非常简单,每一行都根据 Switch 函数的每个 case 表达式求值。当一行匹配条件时,有一个 Not Started 值,即下一行根据 Switch 函数中的每个条件进行评估,依此类推。

Note the cases are evaluated in the order they were written. So in our scenario every row is evaluated firstly against the condition where it contains Not Started values if the condition is false, it continues to the next condition, if it is false it continues to the next condition and so on, until a condition is true or all conditions are evaluated.

如果有帮助请告诉我。