views:

91

answers:

2

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.

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

Any help would be greatly appreciated!

Thanks!

Emo

+4  A: 

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.

Alison
I'm not sure if I'm missing something here, but I'm still getting the entire string as red, not just the 160 value. I cleared the cell out completely and started from sratch. Created the placeholder and in the placeholder selected the field Store_Number. Then selected "HTML, interpret HTML tags as styles". I also made sure that the Placeholder "Font" properties still has the expression =iif(Fields!Store_Number.Value.ToString().Contains (Fields!DMHomeStore.Value)= True,"Red","Black")Then did the second step adding the =Replace expression you gave me.
Emo
Take away the expression from the font property. You don't want to set the color in two places.
Alison
Ok, tried that, but now I'm just getting the entire row as black. Without that iif expression, what should be making the text red? Sorry...I've never been good at using expressions.
Emo
Am I supposed to be adding HTML code too? If so, where?Thanks again!
Emo
You're right. I just noticed that my HTML wasn't being displayed. It was there in my solution but the site wasn't showing my HTML tags in the displayed answer. I put a few "dummy" spaces and now the tags are showing properly. Just make sure to clean up the tags and you should be good to go.
Alison
I just added the appropriate Markdown and the HTML is now displaying perfectly.
Alison
Perfect! That did it. Thanks so much Alison. But now another problem has arisen....if the DMHomestore is 19, it's also changing the "19" in 190, 191, 192...etc
Emo
It's possible to handle this case but you'll end up with a long string of multiple "replace" functions that each account for a different position of the desired string. It's doable but ugly...but still doable.
Alison