我正在尝试在我的报告中为Cell写一个字段表达式,我必须根据单元格中的字符串值更改单元格的背景颜色。例如:如果列中包含值“已批准”,则单元格应显示绿色背景颜色。我尝试了以下方法:
= IIF(fields!column.value = "Approved", "Green")
和
= IIF(Fields!column.Value, "Approved", "Green")
两者都没有...我知道我在语法中缺少一些东西..可能我并没有将绿色指向语法中的背景颜色。请帮忙!
IIF(Fields!column.Value =“Approved”,“Green”)的问题在于您缺少第三个参数。正确的语法是IIF([某个布尔表达式],[结果如果布尔表达式为真],[结果如果布尔值为假])
试试这个
=IIF(Fields!Column.Value = "Approved", "Green", "No Color")
以下是Expression Examples in Reporting Services的表达式示例列表
使用Color和Backcolor属性为查询编写表达式。将以下内容添加到要为其提供的颜色属性的表达式选项中
例
=iif(fields!column.value = "Approved", "Green","<other color>")
iif
需要3个值,首先是相关的Column,然后第二个是处理True,第三个是处理iif
语句的False
= IIF(字段!column.value =条件,“红色”,“黑色”)
= IIF(领域!ADPAction.Value.ToString()。ToUpper的()。包含( “失败”), “红”, “白”)
还需要转换为大写进行比较才是二进制测试。
您可以使用SWITCH()函数来评估多个条件以为单元格着色。节点<BackgroundColor>
是单元格填充,<Color>
是字体颜色。
表达:
=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节点(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>