简体   繁体   English

SSRS 2008 中的开关和 IIF 条件格式

[英]Switch & IIF Conditional Formatting in SSRS 2008

I'm am having some trouble with conditional formatting in SSRS.我在使用 SSRS 中的条件格式时遇到了一些问题。 I have tried Switch & IIF Statements (below).我试过 Switch 和 IIF 语句(如下)。 The report runs but is not returning colors as it I'm hoping it would.该报告运行但没有像我希望的那样返回 colors。 I'm trying to highlight dates which are <= today in red, and everything else will be black.我试图用红色突出显示 <= 今天的日期,其他所有内容都是黑色的。 Does it matter if this field is a date field?该字段是否为日期字段有关系吗? I've seeen other questions on here with the same issues but no resolutions.我在这里看到了其他有相同问题但没有解决方案的问题。 Was hoping today would be my lucky day to find an answer.希望今天是我找到答案的幸运日。 Here is what I have tried and thank you in advance for any input.这是我尝试过的方法,在此先感谢您的任何意见。

        =Switch( Fields!Decision_Must_Be_Made.Value <= today(), "Red",  
         Fields!Decision_Must_Be_Made.Value > today(),  "Black")

        =IIF( Fields!Decision_Must_Be_Made.Value <=today(), "Red",  "Black")

Yes, it definitely matters if the field is a Date Time field.是的,如果该字段是日期时间字段,那肯定很重要。 If it's a string, then you need to convert it to datetime first.如果它是一个字符串,那么你需要先将它转换为日期时间。 How you do that will depend on the format of the string.你如何做取决于字符串的格式。 But it will be much better if you can stick with a datetime field from the database.但是,如果您可以坚持使用数据库中的日期时间字段,那就更好了。 (I've seen where some will format a date to a string in the select of the sql query. Don't do that. Format as late as possible: in SSRS, at the text box level.) (我看到有些人会将日期格式化为 sql 查询的 select 中的字符串。不要那样做。尽可能晚地格式化:在 SSRS 中,在文本框级别。)

If it is a dateTime, break up your formula to find out what's not working as expected and make it more visible, if only for debugging.如果它是一个日期时间,请分解您的公式以找出未按预期工作的内容并使其更加可见,即使只是为了调试。 Put this in the expression of a cell, for example:把它放在一个单元格的表达式中,例如:

=IIF( Fields!Decision_Must_Be_Made.Value <=today(), "Old",  "New")

Edited to add information on where the color formula should be added:编辑以添加有关应在何处添加颜色公式的信息:

Sounds like you don't have the IIF specifying the color in the right place.听起来您没有在正确位置指定颜色的 IIF。 There are a few different places you could specify this: it needs to be in the properties of either the textbox or the placeholder.您可以在几个不同的地方指定它:它需要在文本框或占位符的属性中。 The value for these things should simply be your date field ( =Fields.Decision_Must_Be_Made.Value ) but the font color needs to be specified separately.这些东西的值应该只是您的日期字段 ( =Fields.Decision_Must_Be_Made.Value ),但需要单独指定字体颜色。 One place to do this is in the Text Box Properties dialog.执行此操作的一个地方是在“文本框属性”对话框中。 In the font pane, you need to specify the font color.在字体窗格中,您需要指定字体颜色。 The Fx symbol indicates that you can specify a formula. Fx 符号表示您可以指定一个公式。 Click this button for a place to enter your '=iif...' formula.单击此按钮可以输入“=iif...”公式。

文本框属性字体窗格

Admittedly this does not answer your scenario but may help someone else.诚然,这不能回答您的情况,但可能会帮助其他人。 I had an issue where a stand-alone textbox using a scenario where I wanted to display an error message when there was either no record or duplicate records.我遇到了一个问题,即独立文本框使用的场景是我想在没有记录或重复记录时显示错误消息。 My formula "=IIf(IsNothing(First(Fields.MyField.Value)) Or First(Fields.MyField,Value) <> Last(Fields,MyField,Value). "Red". "SomeOtherColorButNotBlack") which did not render the correct fore-color (came out "Black") however. doing a similar expression that equates to True or False on a Tablix or Matrix does work fine. Another one for MS to solve. I found my own workaround by setting the color to always be red and then the expression of the Text to be blank when no error.我的公式 "=IIf(IsNothing(First(Fields.MyField.Value)) Or First(Fields.MyField,Value) <> Last(Fields,MyField,Value). "Red". "SomeOtherColorButNotBlack") 没有渲染然而,正确的前景色(出现“黑色”)。在 Tablix 或 Matrix 上做一个等同于 True 或 False 的类似表达式确实可以正常工作。MS 需要解决的另一个问题。我通过将颜色设置为始终找到了自己的解决方法当没有错误时,Text 的表达式为红色然后为空白。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM