I'm trying to write a field expression for a Cell in my report where I have to change the background color of the c开发者_开发问答ell depending on the string value in the cell. Ex: if the column has a value 'Approved' in it, the cell should show a green background color. I tried the following:
= IIF(fields!column.value = "Approved", "Green")
and
= IIF(Fields!column.Value, "Approved", "Green")
Neither works.. I know i'm missing something in the syntax.. Probably I'm not refering green to the back ground color in the syntax. Please help!
The problem with IIF(Fields!column.Value = "Approved", "Green") is that you are missing the third parameter. The correct syntax is IIF( [some boolean expression], [result if boolean expression is true], [result if boolean is false])
Try this
=IIF(Fields!Column.Value = "Approved", "Green", "No Color")
Here is a list of expression examples Expression Examples in Reporting Services
Make use of using the Color and Backcolor Properties to write Expressions for your query. Add the following to the expression option for the color property that you want to cater for)
Example
=iif(fields!column.value = "Approved", "Green","<other color>")
iif
needs 3 values, first the relating Column, then the second is to handle the True and the third is to handle the False for the iif
statement
You can use SWITCH() function to evaluate multiple criteria to color the cell. The node <BackgroundColor>
is the cell fill, <Color>
is font color.
Expression:
=SWITCH(
(
Fields!Usage_Date.Value.Contains("TOTAL")
AND (Fields!User_Name.Value.Contains("TOTAL"))
), "Black"
,(
Fields!Usage_Date.Value.Contains("TOTAL")
AND NOT(Fields!User_Name.Value.Contains("TOTAL"))
), "#595959"
,(
NOT(Fields!Usage_Date.Value.Contains("TOTAL"))
AND Fields!User_Name.Value.Contains("TOTAL")
AND Fields!OLAP_Cube.Value.Contains("TOTAL")
), "#c65911"
,(
NOT(Fields!Usage_Date.Value.Contains("TOTAL"))
AND Fields!User_Name.Value.Contains("TOTAL")
AND NOT(Fields!OLAP_Cube.Value.Contains("TOTAL"))
), "#ed7d31"
,true, "#e7e6e6"
)
'Daily Totals... CellFill.&[Dark Orange]-[#c65911], TextBold.&[True]'Daily Totals... CellFill.&[Dark Orange]-[#c65911], TextBold.&[True]
'Daily Cube Totals... CellFill.&[Medium Orange]-[#eb6e19]
'Daily User List... CellFill.&[Light Grey]-[#e7e6e6]
'Date Totals All Users Total... CellFill.&[Black]-["black"], TextColor.&[Light Orange]-[#ed7d31]
'Date Totals Per User... CellFill.&[Dark Grey]-[#595959], TextColor.&[Yellow]-["yellow"]
'(ALL OTHER CONDITIONS)
'Daily User List... CellFill.&[Light Grey]-[#e7e6e6]
XML node in report definition file (SSRS-2016 / VS-2015):
<TablixRow>
<Height>0.2in</Height>
<TablixCells>
<TablixCell>
<CellContents>
<Textbox Name="Usage_Date1">
<CanGrow>true</CanGrow>
<KeepTogether>true</KeepTogether>
<Paragraphs>
<Paragraph>
<TextRuns>
<TextRun>
<Value>=Fields!Usage_Date.Value</Value>
<Style>
<FontSize>8pt</FontSize>
<FontWeight>=SWITCH(
(
NOT(Fields!Usage_Date.Value.Contains("TOTAL"))
AND Fields!User_Name.Value.Contains("TOTAL")
AND Fields!OLAP_Cube.Value.Contains("TOTAL")
), "Bold"
,true, "Normal"
)</FontWeight>
<Color>=SWITCH(
(
Fields!Usage_Date.Value.Contains("TOTAL")
AND (Fields!User_Name.Value.Contains("TOTAL"))
), "#ed7d31"
,(
Fields!Usage_Date.Value.Contains("TOTAL")
AND NOT(Fields!User_Name.Value.Contains("TOTAL"))
), "Yellow"
,(
NOT(Fields!Usage_Date.Value.Contains("TOTAL"))
AND Fields!User_Name.Value.Contains("TOTAL")
AND Fields!OLAP_Cube.Value.Contains("TOTAL")
), "Black"
,(
NOT(Fields!Usage_Date.Value.Contains("TOTAL"))
AND Fields!User_Name.Value.Contains("TOTAL")
AND NOT(Fields!OLAP_Cube.Value.Contains("TOTAL"))
), "Black"
,true, "Black"
)
'Daily Totals... CellFill.&[Dark Orange]-[#c65911], TextBold.&[True]'Daily Totals... CellFill.&[Dark Orange]-[#c65911], TextBold.&[True]
'Daily Cube Totals... CellFill.&[Medium Orange]-[#eb6e19]
'Daily User List... CellFill.&[Light Grey]-[#e7e6e6]
'Date Totals All Users Total... CellFill.&[Black]-["black"], TextColor.&[Light Orange]-[#ed7d31]
'Date Totals Per User... CellFill.&[Dark Grey]-[#595959], TextColor.&[Yellow]-["yellow"]
'(ALL OTHER CONDITIONS)
'Daily User List... CellFill.&[Light Grey]-[#e7e6e6]</Color>
</Style>
</TextRun>
</TextRuns>
<Style />
</Paragraph>
</Paragraphs>
<rd:DefaultName>Usage_Date1</rd:DefaultName>
<Style>
<Border>
<Color>LightGrey</Color>
<Style>Solid</Style>
</Border>
<BackgroundColor>=SWITCH(
(
Fields!Usage_Date.Value.Contains("TOTAL")
AND (Fields!User_Name.Value.Contains("TOTAL"))
), "Black"
,(
Fields!Usage_Date.Value.Contains("TOTAL")
AND NOT(Fields!User_Name.Value.Contains("TOTAL"))
), "#595959"
,(
NOT(Fields!Usage_Date.Value.Contains("TOTAL"))
AND Fields!User_Name.Value.Contains("TOTAL")
AND Fields!OLAP_Cube.Value.Contains("TOTAL")
), "#c65911"
,(
NOT(Fields!Usage_Date.Value.Contains("TOTAL"))
AND Fields!User_Name.Value.Contains("TOTAL")
AND NOT(Fields!OLAP_Cube.Value.Contains("TOTAL"))
), "#ed7d31"
,true, "#e7e6e6"
)
'Daily Totals... CellFill.&[Dark Orange]-[#c65911], TextBold.&[True]'Daily Totals... CellFill.&[Dark Orange]-[#c65911], TextBold.&[True]
'Daily Cube Totals... CellFill.&[Medium Orange]-[#eb6e19]
'Daily User List... CellFill.&[Light Grey]-[#e7e6e6]
'Date Totals All Users Total... CellFill.&[Black]-["black"], TextColor.&[Light Orange]-[#ed7d31]
'Date Totals Per User... CellFill.&[Dark Grey]-[#595959], TextColor.&[Yellow]-["yellow"]
'(ALL OTHER CONDITIONS)
'Daily User List... CellFill.&[Light Grey]-[#e7e6e6]</BackgroundColor>
<PaddingLeft>2pt</PaddingLeft>
<PaddingRight>2pt</PaddingRight>
</Style>
</Textbox>
<rd:Selected>true</rd:Selected>
</CellContents>
</TablixCell>
=IIF(Fields!ADPAction.Value.ToString().ToUpper().Contains("FAIL"),"Red","White")
Also need to convert to upper case for comparision is binary test.
Try this: =IIF(fields!column.value =Condition,"Red","Black")
Try this: =IIF(Fields!Column.Value = "Approved", "Green", "No Color")
精彩评论