What is difference between IIF and Switch Function in SSRS Report - SSRS Interview Questions and Answers

IIF works pretty much like if else,if the expression is true, then we use the first part otherwise use the second part.

Let's say if I have a field called ItemsSold and I want to change the color of cell. I would like to change the color to Yellow if ItemsSold value<=5 otherwise Green.

here is how I will use IIF function

=IIF(Fields!ItemsSold.Value<=5,"Yellow","Green")


Switch works like case statement. We can write multiple conditions.Switch evaluate them in sequence and take the first expression that evaluated to true.

Let's write switch function by using ItemsSold field. If value<=3 we want to have red color for our cell, if ItemSold value<=6 we would like to have it yellow and any value for ItemSold>6, we want to have green color.

=Switch(Fields!ItemsSold.Value<=3,"Red",Fields!ItemsSold.Value<=6,"Yellow",Fields!ItemsSold.Value>6,"Green")