Emo
Emo

Reputation: 496

Expression to change specific value text color in string of values in SSRS based on another field

I have a field in my SSRS report, that contains a string of numbers delimited with commas (from a coalesce select in SQL). It looks like 12, 91, 160, 171, 223. I would like to change the text color of only ONE specific value (160 for example) in the field, IF the value is also in another field of the report.

I already have this for an expression for the Font of the field properties.

=iif(Fields!Store_Number.Value.ToString().Contains (Fields!DMHomeStore.Value)= True,"Red","Black")

This changes the text color of the entire field, not just that ONE value in the string.

Basically, if DMHomeStore = 160, and Store_Number has 160 in it's string, then make only 160 Red in the Store_Number string.

Upvotes: 4

Views: 25927

Answers (2)

BobC
BobC

Reputation: 100

SSRS will not render all html tags, for example styling will get dropped from span tags. Heres a good reference http://dinesql.blogspot.com/2010/05/reporting-services-2008-showing-html.html

Upvotes: 1

NakedBrunch
NakedBrunch

Reputation: 49413

This can certainly be done and isn't difficult to do.

  1. Start with an empty table cell.
  2. Double click on the cell -> Right-Click -> Create Placeholder
  3. On the General tab, Value -> select the field that will contain the string of numbers
  4. On the same General tab, select "HTML, interpret HTML tags as styles
  5. Click OK

That's the first step. Now, all we need to do is set up an expression that will find the string in question and then replace it with HTML code to make it red.

  1. Right-click on the cell -> Select Expression
  2. Enter the following expression:
=Replace(Fields!Store_Number.Value.ToString(),Fields!DMHomeStore.Value," `<span style='color:red'>` " & Fields!DMHomeStore.Value & "`</span>`")

Run your report and only the string in question will be red and all other text in the cell will be black. If the string in question isn't found then all other text will be black.

Upvotes: 7

Related Questions