Display Image Based on SSRS Expression

This SSRS article shows how to display images based on the IIf or switch expression with an example. To do this, right-click on the Datasets folder to create a new DataSet. 

The screenshot below shows the data set we use for this display Image Based on the SSRS Expression example.


The Sql query that we used above SSRS example is:

SELECT [FirstName] +  ' ' + [LastName] AS FullName
  FROM [Employee]

We have designed a simple table report of Employee Sales and formatted the font and colors.

Display Image Based on SSRS Expression

To display the image, add a new column by right-clicking the Sales column, choosing the insert column, and then the Right option. 

Add a New Column

Rename that column header as the Image. Next, right-click on the Images folder and choose Add Image option.

Choose Add Image Option

Select the required Image. As you can see, first, we have chosen the London palace. Similarly, we will add Music Concert and Cookies images as well. 

Upload Images to Display  them Based on SSRS Expression

You can see all these three images under the Images folder within the Report Data window. Next, right-click on the empty cell, choose Insert, and then the Image option. 

Choose Insert and then Image option

It opens the following Image Properties window. Click that little ƒx button to write the expression.

Click the fx

Here, we used the Nested IIF condition. The first condition checks whether the Sales value is less than 1000. If True, display the Cookies image. Otherwise, the second iif condition matches whether the Sales value is less than 3000. If True, Music Concerts else show the London palace image.

=IIf(Fields!Sales.Value < 1000, "Cookies", 
IIf(Fields!Sales.Value < 3000, "MusicConcert", "LondonPalace"))
Display Image Based on SSRS IIF Expression

Remember, if you want to test more conditions, use the switch statement.

=Switch(Fields!Sales.Value < 1000,"Cookies",
	Fields!Sales.Value < 3000,"MusicConcert",
	Fields!Sales.Value >= 3000,"LondonPalace")

Click Ok to close the Image properties window.

Close the Properties Window

And the final report is.

Display Image Based on SSRS Expression report

Now, if you go to the SSRS table report preview, it displays different images based on our provided expression. 

Display Image Based on SSRS Expression Preview