Search code examples
reporting-servicesssrs-2012

SSRS expression that evaluates if any string in group matches parameter


I have a SSRS report that contains the following DataSet.

 Foo | Bar
-----------
  1  |  A
  2  |  A
  2  |  B

I am displaying this data in a Tablix, there is a row grouping on Foo.

 Foo | Quantity
----------------
[Foo]|[Count(Bar)]

The above produces:

 Foo | Quantity
----------------
  1  |    1
  2  |    2

I also have a string parameter bar, when this parameter matches any of the values of Bar found in the row group I would like to highlight the Quantity cell.

i.e.

=IIf(Fields!Bar.Value = Parameters!bar.Value, "Plum", "Orange")

If bar is set to 'A', the above expression will provide the desired behavior for Foo = 1, but not Foo = 2.

I saw a similar question related to booleans, but the solution does not work with strings. Perhaps SSRS has some Any or Contains functionality I'm not familiar with?


Solution

  • If I understood correctly....

    I think your issue is that you are trying to evaluate each row to see if Bar matches your parameter but the cell you want to highlight is an aggregate - its value is based on several rows of data potentially.

    You should be able to just get a count of matching rows and if that is greater than zero, then highlight the cell. For example

    =IIF(
        SUM(IIF(Fields!Bar.Value = Parameters!bar.Value,1,0)) > 0
        , "Plum"
        , "Orange"
        )
    

    This just evaluates each row to either 1 or 0 (match or no match), sums the results and if it's greater than 0 (we found a match) then return "Plum"