IIF和颜色填充

时间:2019-08-06 19:51:37

标签: reporting-services

我想在SSRS中进行简单的颜色填充。 如果演员的名字不是John Cena或Brad Pitt,则以黄色突出显示。 我正在尝试以下方法:

 =IIF(Fields!PrimaryUserName.Value <> "John Cena" OR (Fields!PrimaryUserName.Value <> "Brad Pitt"), "Black", "Yellow")

但这最终将所有内容填充为黄色。

3 个答案:

答案 0 :(得分:0)

我相信您的问题源于对字符串值使用not equals运算符。我认为您最好将此功能与Contains函数一起使用。尝试以下表达式:

=IIF(Fields!PrimaryUserName.Value.Contains("John Cena") 
     OR (Fields!PrimaryUserName.Value.Contains("Brad Pitt"), "Black", "Yellow")

另一个可行的选择是使用InStr函数,如下所示:

=IIF(Instr(Fields!PrimaryUserName.Value("John Cena") > 0
     OR Instr(Fields!PrimaryUserName.Value("Brad Pitt") > 0, "Black", "Yellow")

好的,我不确定您使用的是哪种版本的Report Builder,但还有其他可能的解决方案。

=IIF(Fields!PrimaryUserName.Value LIKE "*John Cena*" 
     OR Fields!PrimaryUserName.Value LIKE "*Brad Pitt*", "Black", "Yellow")

如果第三个表达式不起作用,最好在查询中添加一列并在SQL中设置此值。

SELECT 
    CASE WHEN PrimaryUserName LIKE "%John Cena%" 
           OR PrimaryUserName LIKE "%Brad Pitt%" 
         THEN "Black" 
         ELSE "Yellow" END As CellColor

然后,只需将单元格颜色设置为=Fields!CellColor.Value,它就可以适当地为事物着色。

答案 1 :(得分:0)

问题出在您的比较中,这对每个名称都是正确的-“ John Cena”不等于“ Brad Pitt”,因此表达式的这一部分将成立,并且因为您使用的是OR,因此整个表达式都将成立,“ Brad Pitt”则相反。每个名称都不等于“ John Cena”和“ Brad Pitt”,包括“ John Cena”和“ Brad Pitt”,因此您总会发黄。您应该使用let newAddedArray = self.userProfile["specialities"] as! Array<Dictionary<String, Any>> for item in newAddedArray { self.addedArray.append(["id" : item["id"]!, "text" : item["name"]!]) } self.specialitiesAdded.reloadData() getSpecialities(){ result in for item in result { self.allArray.append(["id" : item["id"]!, "text" : item["text"]!]) } self.specialitiesAll.reloadData() } 而不是=

您要执行的操作是检查名称是否等于“ John Cena”或“ Brad Pitt”,并用其他所有颜色为黄色的颜色涂上黑色:

<>

答案 2 :(得分:0)

这是我的输出 enter image description here

转到该单元格的TextBox属性

enter image description here

我用下面的表达式

=IIF((LCase(Fields!ActorName.Value)=LCase("John CEna")
OR LCase(Fields!ActorName.Value)=LCase("BraD PIT"))
,"Yellow","Green")