ssrs iif expression

In this SSRS Tutorial I will show you IIF expression which is also know and IF THEN ELSE statement that allows to provide a condition that can be evaluated to either TRUE or FALSE and provide a value for TRUE part and for FALSE part. In this SSRS Tutorial I will use SQL Server Reporting Services 2008 R2 but it should work with SSRS 2005, 2008 and 2012.

To create SSRS IIF expression please follow my tutorial.

In my example I will check if a person lives in Bristol if yes I will display Yes in a separate column and if not the cell will be blank.

 

I already have SSRS report and a table and I have fields Surname, City and Country. I insert new column to the right that will contain SSRS IIF expression.

 

I will call the new columm header 'Lives in Bristol' and I will add IIF expression. To add expression I right click the cell and click expression command.

Expression dialog box appears where I will use IIF function. The first argument is condition and in my case I check if field values is = "Bristol" if yes then "Yes" else "" which means if field value = "Country" then it will return true part of IIF function which is second argument in my case I have values "Yes" else is my false part which means that if City does not equal "Bristol" it will return empty string "" and false part is a third argument n the inline IF (IIF) function.

Below is an example of IIF Expresion

Let's preview our report. You can see our IIF expression worked and if someones lives in Bristol then we get YES else we get nothing.

I hope this SSRS tutorial will help you to create your own SSRS IIF Expressions.

 

Take care

Katie


SHARE:


Name: Kumar
Comment:

How to set the backgroundcolor of third column Accountname textbox to Red in the matrix report when first column Customername<>'Kumar' in the matrix report?

Please help?

I have tried the below steps.

=IIF(Fields!High_Level_New_Business_Channel.Value<>"Intermediary" and Fields!Account_Manager.Value<>"","Red","White")


above expression not working.Please help me 

 


Date Posted: 12/09/2012 5:14:00 PM

Name: Emil
Comment:

Hi

Try to put field names in separate columns on its own and see if you get the value you want. This generally helps me to debug issues.

Hope that helps

Emil


Date Posted: 15/09/2012 10:43:33 AM

Name: Kumar
Comment:

Thank you very much


Date Posted: 05/03/2013 10:00:46 AM

Name: Bart Mutsaers
Comment:

Hi, I want to know something about the order of evalutation in the conditional part of the IIF statement.

IIF(a>b AND c=d AND e*f<g, true-action, false-action)

How is this evaluated? All three expressions or will it stop as soon it turns out false? In javascript it will stop evaluating the expressions as soon as the outcome is known. For instance in the case a=b the condition will always turn into FALSE, no matter what the other expressions will return. How about the IFF statement in SSRS?

I want to know this because it can make a big difference with respect to performance.


Date Posted: 18/04/2013 9:14:22 AM

Name: Emil
Comment:

Hi

I believe AND will evaluate next condition however you might be able to use AndAlso which won't evaluate next condition if first is not met.

If you are worried about performance you also might be able to gain better performance by doing it in SQL (if possible) with persisted columns (for deterministic calculations).

Take care

Emil


Date Posted: 18/04/2013 9:50:34 AM




Disclaimer: While every caution has been taken to provide our readers with most accurate information and honest analysis, please use your discretion before taking any decisions based on the information in this blog. Author will not compensate you in any way whatsoever if you ever happen to suffer a loss/inconvenience/damage because of/while making use of information in this blog.