Is there a way in SSRS to conditionally set the color of a column?
I want to do something like:
=IFF(some condition, Color(Fields!Date, "Green"), Color(Fields!Date, "Red"))
Yes you go into the Color property of the text box in the Detail row of the table and set the color to an <expression..> then in the dialog that comes up enter somthing like this...
=iif(Fields!Name.Value = "Smith", "Green", "Red")
if the name = smith make the color green other wise make it red
the key point being that you go to the property and set the property equal to an expression.
if you need more value/color options you can put in a little code in the report that you can reference from the expression.
1. right click in the little box at the top left of the report (intersection of the vertical and horizontal rulers) in the designer and choose properties.
2. select the code tab
3. type in some VB code
ex.
Public Function GetColor(ByVal sname as String) as String
IF sname = "Smith" Then
Return "Blue"
End IF
IF sname = "Jones" Then
Return "Black"
End IF
IF sname = "Woods" Then
Return "Red"
End IF
End Function
4. set the color or background property to =code.GetColor(Fields!Name.Value)
================= off topic FYI
here is another example of a little code for the report that can be used in an expression
this is used in a calulated field in a dataset =Code.GetBox(Fields!Percentile.Value,Fields!Importance.Value)
Public Function GetBox(ByVal PercentImp As Integer, ByVal Important As Integer) As Integer
Select Case Important
Case 1
Select Case PercentImp
Case 0 To 39
GetBox = 1
Case 40 To 75
GetBox = 2
Case Is > 75
GetBox = 3
End Select
Case 2
Select Case PercentImp
Case 0 To 39
GetBox = 4
Case 40 To 75
GetBox = 5
Case Is > 75
GetBox = 6
End Select
Case 3
Select Case PercentImp
Case 0 To 39
GetBox = 7
Case 40 To 75
GetBox = 8
Case Is > 75
GetBox = 9
End Select
End Select
End Function
|||You've made my day. Totally sweet. Thank you!!!
No comments:
Post a Comment