首页 > 解决方案 > SSRS Conditional formatting USING CONTAINS

问题描述

I'm new to SSRS and I am trying to apply conditional formatting to a field and I'm getting an error and I can't figure out why I'm getting it. The following is my expressions...

=IIf(Fields!Category.Value.ToString().Contains("TIA"),"GREEN",
IIf(Fields!Category.Value.ToString().Contains("IR"),"PURPLE",
IIf(Fields!Category.Value.ToString().Contains("TPA"),"PURPLE",
IIf(Fields!Category.Value.ToString().Contains("ICH"),"RED",
IIf(Fields!Category.Value.ToString().Contains("SAH"),"RED",
TRUE,"TRANSPARENT")))))

标签: reporting-servicesformattingconditional-statementsexpression

解决方案


It looks like you have mixed the syntax for IIF and SWITCH (the 'True' at the end looks typically from a SWITCH statement)

In this case SWITCH is usually easier to read..

try this

=SWITCH
    (
        Fields!Category.Value.ToString().Contains("TIA"), "Green",
        Fields!Category.Value.ToString().Contains("IR") , "Purple",
        Fields!Category.Value.ToString().Contains("TPA"), "Purple",
        Fields!Category.Value.ToString().Contains("ICH"), "Red",
        Fields!Category.Value.ToString().Contains("SAH"), "Red",
        TRUE, Nothing
    )

I used Nothing rather than transparent as that is the default for a cell background. Both should work, I just prefer Nothing as that is internally the default for a cell background.


推荐阅读