SSRS - Conditional Text Formatting (Expressions using Switch)

Facegames TC picture Facegames TC · Jun 12, 2013 · Viewed 13.8k times · Source

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:

enter image description here

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).

Answer

djangojazz picture djangojazz · Jun 12, 2013

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.