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.
SELECT [FirstName] + ' ' + [LastName] AS FullName ,[Education] ,[Occupation] ,[YearlyIncome] ,[Sales] ,[HireDate] 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.
Rename that column header as the Image. Next, right-click on the Images folder and 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.
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 the final report is.
Now, if you go to the SSRS table report preview, it displays different images based on our provided expression.