根据从先前值到当前值SSRS的值的差异来更改颜色

时间:2017-10-05 13:20:50

标签: visual-studio reporting-services

我正在尝试将当前行值与前一行值进行比较,但仅在同一组中。

我有Group1(Plant),ChildGroup1(DeviceTag),Details Group, 我在Fill属性中尝试了这个代码,但它不起作用,它似乎每次都会改变每一组第一行的颜色,而不管前一行的值。

if {#ChangeCounter}=1 then nocolor else
if currentfieldvalue <> previous({DataSet.Field}) then cryellow else nocolor

所以我的数据集如下所示:

Plant       DeviceTag       Description    Location

  A            Tag1            ABCD          West
               Tag1            WXYZ          West      DeviceTag Group 1
_____________________________________________
  A            Tag2            EFGH          East
               Tag2            IJKL          East      DeviceTag Group 2
               Tag2            IJKL          West

在这两个DeviceTag组中,描述已更改,因此我想将ABCD的颜色更改为黄色,将EFGH更改为黄色而不是WXYZ,因为它与EFGH不在同一组中。第二行说东方应该是黄色,因为它与前一个西方位置不同。

在Crystal Reports中,您可以这样做:

int i=0;int j=101;
while(computerGuess != userGuess) {

    if(computerGuess > userGuess) {
        j=computerGuess;
        System.out.println("Guess lower: ");
        computerGuess = guess.nextInt(j);
        System.out.println(computerGuess);
    }else if(computerGuess < userGuess) {
        i=computerGuess;
        System.out.println("Guess higher: ");
        //computerGuess = guess.nextInt(101);
        computerGuess = guess.nextInt(j - i) +i;
        System.out.println(computerGuess);
    }
    amountTries++;
}

公式#ChangeCounter只是1

清除泥浆?

2 个答案:

答案 0 :(得分:1)

我总是在数据集查询中发现这种事情更容易(假设您可以控制数据集中的查询)。

操纵您的最终数据集(SSRS将收到的数据集)以获得另一列,告知SSRS是否为单元格着色。并将您的业务逻辑保留在数据库查询中。

您可以使用row_number()为每一行(在每个组中)编号,然后在新的行号列上将表连接回自身。

也许这样的事情?我不确定我是否100%遵循您的单元格着色逻辑,我确信您的数据集大于您提供的数据集,但您可以根据自己的需要对其进行调整。

;with Data as 
(
    select 'A' as Plant, 'Tag1' as DeviceTag, 'ABCD' as Description, 'West' as Location union all
    select 'A' as Plant, 'Tag1' as DeviceTag, 'WXYZ' as Description, 'West' as Location union all
    select 'A' as Plant, 'Tag2' as DeviceTag, 'EFGH' as Description, 'East' as Location union all
    select 'A' as Plant, 'Tag2' as DeviceTag, 'IJKL' as Description, 'East' as Location union all
    select 'A' as Plant, 'Tag2' as DeviceTag, 'IJKL' as Description, 'West' as Location
),

DataWithRowNumbers as
(
select
    *,
    row_number() over (partition by DeviceTag order by Description) as DeviceTagGroupRowNumber
from
    Data    
)

select
    a.*,
    case when a.Description != b.Description then 'Yellow' else 'Transparent' end as CellColor
from
    DataWithRowNumbers a
    left join DataWithRowNumbers b on a.DeviceTag = b.DeviceTag and a.DeviceTagGroupRowNumber = b.DeviceTagGroupRowNumber - 1

然后,您可以将单元格中的背景(在SSRS中)设置为只有Fields!CellColor.Value的表达式。

答案 1 :(得分:0)

您需要使用Previous函数的Scope参数,提供ChildGroup1(DeviceTag)的名称。 e.g。

= IIf(Fields!DeviceTag.Value&lt;&gt; Previous(Fields!DeviceTag.Value,“ChildGroup1”),“Yellow”,“White”)

这是doco:

https://docs.microsoft.com/en-us/sql/reporting-services/report-design/report-builder-functions-previous-function