0

I want to use conditional formatting to change the color of a row based on a Calculated Column. I know I could do this with a CEWP but I would prefer to do it in SPD 2010 because I am new to programming and another non-programmer may be tasked to maintain this later.

The calculated column has values from -1 through 5 and I want to grey out everything that is less than 1. The "type" of the calculated column is "Number" in Column Settings.

Condition for formatting: Field Name: # Available; Comparison: Less Than; Value: 1

Style to be applied: background-color: #D6D6D6; color: #3F3F3F

I get no result. Same if I change the comparison to be IsNull or anything else. The conditional formatting works fine when I use other columns for the comparison. e.g. Condition for formatting is "Preferred Setting" (a choice column) equals "One-on-one" (one of the choices).

Is there anything special I can do to allow SPD to interpret my Calculated Column and use it for formatting?

2
  • You shouldn't have to do anything special to enable conditional formatting based on a calculated column in SPD. Sometimes formatting choices don't work right away, so try a number of options (e.g. different colors, bold text). Also, share your exact conditional formula for further troubleshooting.
    – Phil Greer
    Mar 27, 2014 at 14:40
  • I have updated the original question with a screenshot of Condition and Style. The strangest thing to me is that it works fine for any other column I use to set the condition.
    – Antimony
    Mar 27, 2014 at 14:55

2 Answers 2

1

Even though your calculated column has the correct type ("number") in SharePoint, you may need to explicitly cast the variable to type number. That's much easier than it sounds.

Do the following in SPD:

  1. Setup your condition and style the way you want them
  2. Go into Code view and look for <xsl:attribute name="style">
  3. Change your condition from <xsl:if test="$thisNode/@_x0023__x0020_Available_x0020_to. = 0" to <xsl:if test="number($thisNode/@_x0023__x0020_Available_x0020_to) = 0" (wrapped the field name in "number()" and omitted the "." at end of field name)
  4. Save and refresh

Thanks for updating your question. Hope my solution works for you!

4
  • Thank you, that did the trick! My final code was slightly different because I did "Less Than 1" : <xsl:if test="number($thisNode/@_x0023__x0020_Available_x0020_To) &lt; 1" I really appreciate your help, I had been searching for this solution for quite some time. Thank you!
    – Antimony
    Mar 27, 2014 at 20:52
  • No problem at all. I'm glad that worked!
    – Phil Greer
    Mar 27, 2014 at 20:57
  • I was having the same issue and this solution worked for me also; Thank you. However, I have been trying to use this solution with a condition that has more than one clause (for example, I wanted to produce results "under the less than 60 AND equal to or greater than 30). Please help.
    – user30321
    Jul 7, 2014 at 17:49
  • @KenT. Try casting to a number in the first part of your comparison, but not the second. For example, <xsl:if test="number($thisNode/@Priority) &gt; 30 and $thisNode/@Priority. &lt;= 60"... Worked for me. Not exactly sure why it works, but I have a few theories : )
    – Phil Greer
    Jul 8, 2014 at 16:34
0

I wanted to give an additional answer - since I had the exact same question as stated by the O.P. - but my problem turned out to be of a completely different nature...

Initially, my conditional formatting logic (an advanced expression) - at the point I made it depend on a calculated column, it seemed to stop working.

However, the actual culprit wasn't the calculated column, itself. The conditional logic didn't actuate because the calculated column had to first be added to the list of visible fields (which, I think is a lame requirement)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.