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 code below shows the data set we use for this display Image Based on the SSRS Expression example.
We have designed a simple table report of Employee Sales and formatted the font and colors. The Sql query that we used above SSRS example is:
SELECT [FirstName] + ' ' + [LastName] AS FullName
,[Education],[Occupation] ,[YearlyIncome],[Sales] ,[HireDate]
FROM [Employee]
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.
Rename that column header as the Image. Next, right-click on the Images folder and choose the 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.
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.
It opens the following Image Properties window. Click that little ƒx button to write the expression.
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"))
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 and check the final report for formatting.
Now, if you go to the SSRS table report preview, it displays different images based on our provided expression.