SSRS - Conditional Text Formatting (Expressions using Switch)

倖福魔咒の 提交于 2019-12-12 13:35:09

问题


I will open this up by stating that the expressions do work within the report. The problem is they aren't working together.

I currently have a column header formatted based on the values of two columns. Italics and underlined based on the value of Column1. Bold and a specific color based on the value of Column2. I am doing this by using Switch expressions in the text properties. Here is what I have for each:

=Switch(Fields!Column1.Value <> "Specific Value","Italic",Fields!Column1.Value = "Specific Value","Normal")
=Switch(Fields!Column1.Value <> "Specific Value","Underline",Fields!Column1.Value = "Specific Value","None")
=Switch(Fields!Column2.Value <= 7,"ExtraBold",Fields!Column2.Value >=` 8,"Normal")
=Switch(Fields!Column2.Value <= 7, "Red",Fields!Column2.Value >= 8,"#586d7f")

And an image to show they are all marked:

When I run the report there are no errors.

The odd thing (to me at least) is the results should look like this:

  1. Normal
  2. Bold and red
  3. Italics and underlined
  4. All four (Bold, Italics, red, and underlined)

In a situation where the text should look like 4 it looks like 2. Everything else is working how it is supposed to so I am a bit stumped and would like an explanation for why this is the case. I looked to see if this had been answered before, but based on what I saw it doesn't seem like it. If I used any of the wrong terminology I apologize (I am pretty new to this).


回答1:


I would use an IIF() statement instead.

=IIF(Fields!Column1.Value <> "Specific Value", "Italic", "Normal") 

Generally speaking a switch is a 'case' statement for multiple occurences and an IIF statement is a typical 'if, then, else' statement. The danger becomes that you can nest IIF statements like IIF(thing, 'set1', iif(thing2, 'set2', 'default')) but it would be easier to do a switch like Switch(thing, 'set1, thing2, 'set2', 'default'). The problem with switches is if an occurence of something happens of both one thing and another it assumes the first is true and just performs that. Thus you must account for proper order of something's occurence or it will assume the first instance. Generally when you have an instance of something and a default I use IIF. If there is a problem with a switch I will do a nested IIF generally or reorder the events of the Switch statement.

I hope that helps a little bit.



来源:https://stackoverflow.com/questions/17068048/ssrs-conditional-text-formatting-expressions-using-switch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!