Search code examples
reporting-servicesssrs-tablix

Conditionally format certain cells of tablix


Using Visual Studio 2017 (SSDT), I have a tablix where I would like to use an expression to set the background color/fill. I would like the cells to fill gray where the:

  1. 2019 Metal is Silver and 2020 Metal is Bronze, or
  2. 2019 Metal is Gold and 2020 Metal is Bronze, or
  3. 2019 Metal is Gold and 2020 Metal is Silver.

Visually, like this:

enter image description here

The data set populating the tablix is:

enter image description here

(I added custom "Is Null" code to display zeros instead.)

I've been trying IIF statement logic but have been unable to get my desired results.

The design of the tablix is:

enter image description here

I'm trying to set the Fill BackgroundColor on the textbox here with an expression:

enter image description here

...using something like:

=IIF(
Fields!METAL_YEAR_2020.Value="Bronze" AND 
  (Fields!METAL_YEAR_2019.Value = "Silver" OR Fields!METAL_YEAR_2019.Value = "Gold")
, "Gray"
, "Transparent"
)

If I leave out the OR condition I can fill one intended cell, but I don't know how to account for the three cells.

So, this code below sets one cell but can I nest or SWITCH to set the three cells I want?

= IIF(
       (
           (Fields!METAL_YEAR_2019.Value = "Silver" and Fields!METAL_YEAR_2020.Value = "Bronze")
        OR (Fields!METAL_YEAR_2019.Value = "Gold"   and Fields!METAL_YEAR_2020.Value = "Bronze")
        OR (Fields!METAL_YEAR_2019.Value = "Gold"   and Fields!METAL_YEAR_2020.Value = "Silver")
       )
, "Gray", "White")

enter image description here


Solution

  • since there is no data where you get the null values (not only the integer value is absent, but all values, you have to refer to the group value, which is in the textbox)

    = iif(
    (cstr(ReportItems!Metal_2019.Value) = "Silver" AND cstr(ReportItems!Metal_2020.Value) =     "Bronze") OR
    (cstr(ReportItems!Metal_2019.Value) = "Gold"   AND (cstr(ReportItems!Metal_2020.Value) = "Silver" OR cstr(ReportItems!Metal_2020.Value) = "Bronze")),
    "Gray","Transparent")
    

    found at