I have a Report where I want to change the background color of the column(sales) based on the Continent column values. Below is the continent column values.
I tried the following expression under Sales column( background color),
=IIF(Fields!column.Value ="4th Quarter",
SWITCH (
Fields!continents.Value ="Asia", "Green",
Fields!continents.Value = "N America","LIMEGREEN",
Fields!continents.Value ="S America","Yellow",
Fields!continents.Value = "Europe", "Red"
)
, "Dummy Value")
When I preview the report, I can see only Green color for all the rows. I know Switch function in SSRS will return the first expression that it finds true.
I also tried by using only IIF condition, still same issue. Is there a way this can be achieved?
Have you tried something like the following?
=IIF((Fields!column.Value ="4th Quarter") AND (Fields!continents.Value ="Asia"),"Green",
IIF((Fields!column.Value ="4th Quarter") AND (Fields!continents.Value = "N America"),"LIMEGREEN",
IIF((Fields!column.Value ="4th Quarter") AND (Fields!continents.Value ="S America"),"Yellow",
IIF((Fields!column.Value ="4th Quarter") AND (Fields!continents.Value = "Europe"), "Red",
"Dummy Value"))))
Related
i have this Conditional Field
=iif(Fields!ENTRADA.Value>Fields!Hora_IN.Value,"Yellow", "white")
But i wanna Add another condition:
i have another field: abrv
What i wanna do is:
Iff abrv.Value=F.C and (DATEDIFF( MI , #ENTRADA.Value , #Hora_IN.Value ) )>15 "Yellow", "white"
ELSE =iif(Fields!ENTRADA.Value>Fields!Hora_IN.Value,"Yellow", "white"),
Can i do that?
Yes you can do that. You actually still only have 2 potential outcomes, since two of those result in Yellow, so you can do this within one IIf statement:
=IIf(
(Fields!abrv.Value = "F.C" and datediff(MI, Fields!ENTRADA.Value, Fields!Hora_IN.Value) > 15)
or
(Fields!ENTRADA.Value > Fields!Hora_IN.Value),
"Yellow",
"White"
)
Or, you can use Switch, since you are checking 3 different conditions.
=Switch(
Fields!abrv.Value = "F.C" and datediff(MI, Fields!ENTRADA.Value, Fields!Hora_IN.Value) > 15, "Yellow",
Fields!ENTRADA.Value > Fields!Hora_IN.Value, "Yellow",
true, "White"
)
By putting "true" as the condition on the last line of the switch, that line basically acts as an "else", so anything that did not meet one of the conditions above it will get that value.
I have a requirement to show different text color when one field matches with another three different fields.
I have written below expression,
=IIF(
Fields!OrderBlockLetter.Value = Fields!InstitutionBlockLetter.Value, "Green",
or Fields!OrderBlockLetter.Value = Fields!DegreeBlockLetter.Value, "Orange",
or Fields!OrderBlockLetter.Value = Fields!AwardBlockLetter.Value, "Blue", "No Color")
But its not working. When saving this code it gives error.
I am using SSRS report builder.
You can't use IIF with OR like that. IIF just returns a value if the expression is true and another if it's false. You can nest IIFs to get the desired results but using SWITCH is much simpler. Try this... (not tested but should be close enough)
=SWITCH
(
Fields!OrderBlockLetter.Value = Fields!InstitutionBlockLetter.Value, "Green",
Fields!OrderBlockLetter.Value = Fields!DegreeBlockLetter.Value, "Orange",
Fields!OrderBlockLetter.Value = Fields!AwardBlockLetter.Value, "Blue",
True, "Black"
)
As switch returns on the first true expression, if all the others fail, the final expression is always True so the "Black" will be returned.
EDIT: Actually, "No Color" is not a valid font. You either need to pick black (the default color), or white (to give the appreance of there not being text there)
I am trying to use this expression to change the background colour of a text box within SSRS 2008
=IIF(Fields!Score.Value <=12, "Green", IIF(Fields!Score.Value >=13, "Amber" , IIF(Fields!Score.Value >=19, "Red" ,"White")))
The result is 15 which should pull back an amber colour which it is not doing.
The thresholds for the score field are
High 19-24
Medium 13-18
Low < 12
Try to convert field value to INT, Might be expression considering this as string
=IIF(CInt(Fields!Score.Value) <=12, "Green", IIF(CInt(Fields!Score.Value) >=13, "Amber" , IIF(CInt(Fields!Score.Value) >=19, "Red" ,"White")))
Assuming 'Score' is an INT you just need to swap the tests for >= 13 and >=19 as follows:
=IIF(Fields!Score.Value <=12, "Green", IIF(Fields!Score.Value >=19, "Red" , IIF(Fields!Score.Value >=13, "Orange" ,"White")))
Also 'Amber' isn't a valid colour name so change that to something like 'Orange' too.
SO Post
Current I've got 5 bars in my RS chart - in the future there might be 7 bars or 17 bars or 27 bars!
With a couple of bars I can have an expression like this:
=iif(Fields!Market.Value = "Spain"
,"Gold"
,iif (Fields!Market.Value = "Denmark"
, "Gray"
, iif(Fields!Market.Value = "Italy"
, "Blue"
, "Purple"
)
)
)
If I can't predict how many countries will be included + I'd rather not have to hard code in "Green", "Red" etc how do I change the expression?
I've tried this but it is erroring:
=Switch(Mod(Fields!Rank.Value/CDbl(2))=CDbl(0), "Gold",
Mod(Fields!Rank.Value/CDbl(3))=CDbl(0), "Gray",
Mod(Fields!Rank.Value/CDbl(2))>CDbl(0) "Blue")
Above is the totally incorrect syntax: This works:
=Switch(CDbl(Fields!Rank.Value Mod 2)=CDbl(0), "Gold",
CDbl(Fields!Rank.Value Mod 3)=CDbl(0), "Gray",
CDbl(Fields!Rank.Value Mod 2)>CDbl(0), "Blue")
Ok - the above runs (not sure how!) but the below is based on help from Dominic Goulet and is really easy to follow and nice and expandable to more colours; this is the solution for 5 colours:
=Switch(CDbl(Fields!Rank.Value Mod 5)=CDbl(0), "Gold",
CDbl(Fields!Rank.Value Mod 5)=CDbl(1), "Gray",
CDbl(Fields!Rank.Value Mod 5)=CDbl(2), "Green",
CDbl(Fields!Rank.Value Mod 5)=CDbl(3), "Red",
CDbl(Fields!Rank.Value Mod 5)=CDbl(4), "Pink")
First of all, instead of using many "IIF"s, you should use "Switch", it's leaner that way.
Switch(Fields!Market.Value = "Spain", "Gold",
Fields!Market.Value = "Denmark", "Gray",
Fields!Market.Value = "Italy", "Blue")
Now if you want a color per coutry, you should defenitely store that in your database and pull it out when you need it. That way, a country will always have the same color on every report you have.
It would be better to create a function. For that, go to Report Properties, choose code and type this example :
Public Function Color(ByVal Index as Integer) as String
Select Case Index
Case = 1
return "#a6cee3"
Case = 2
return "#1f78b4"
Case = 3
return "#b2df8a"
Case = 4
return "#33a02c"
Case = 5
return "#fb9a99"
Case = 6
return "#e31a1c"
Case = 7
return "#fdbf6f"
Case = 8
return "#ff7f00"
Case = 9
return "#cab2d6"
Case = 10
return "#6a3d9a"
End Select
End Function
On the Fill option from "Series Properties->Pick color-> Color choose fx
put this code
=Code.Color(rownumber(nothing))
Each bar will have a color.
For the HEX colors I took from the website : http://colorbrewer2.org/#type=qualitative&scheme=Paired&n=10
It shows the best colors that match with each other, so you don't need to think of that. And you can add as many colors as you want
I have a doubt here,
I need to show a pie-chart in SSRS, for the student results according to their status(Pass/Fail).......I have only 4 conditions Male-pass,Male-fail,Female-pass,Female-fail,I need to show these things with my own color,
for this am using the switch condition as
=Switch(
((Fields!Gender.Value = "Male")&(Fields!Status.Value="Pass")), "Blue",
((Fields!Gender.Value = "Male")&(Fields!Status.Value="Fail")), "HotPink",
((Fields!Gender.Value = "Female")&(Fields!Status.Value="Fail")), "Orange",
((Fields!Gender.Value = "Female")&(Fields!Status.Value="Pass")),"LimeGreen" )
but in the preview it shows only the default color set, not the customized one, can anyone fix this one...thanks in advance
Try using something like
=IIf((Fields!Gender.Value = "Male") and (Fields!Status.Value="Pass"),"Green",
IIf((Fields!Gender.Value = "Male") and(Fields!Status.Value="Fail"),"Red" ,
IIf((Fields!Gender.Value = "Female") and (Fields!Status.Value="Fail") ,"Blue",
(Fields!Gender.Value = "Female") and (Fields!Status.Value="Pass"),"Yellow","Orange"
,"#00000000"))))
You should be able to get it working using the Switch statement as well. The problem with your expression is that the logical "and" operator in SSRS is And, not ampersand. In SSRS, a single ampersand is used for concatenating strings. So your expression is concatenating the string representation of the two boolean results, resulting in strings like TrueFalse. This should actually giving an error on the Switch evaluation.
A correct Switch statement would be this:
=Switch(
Fields!Gender.Value = "Male" And Fields!Status.Value="Pass", "Blue",
Fields!Gender.Value = "Male" And Fields!Status.Value="Fail", "HotPink",
Fields!Gender.Value = "Female" And Fields!Status.Value="Fail", "Orange",
Fields!Gender.Value = "Female" And Fields!Status.Value="Pass","LimeGreen"
, True, "SomeOtherColor"
)
I've also added an "else" part to the switch in case some records are not covered by the other conditions. If you're 100% sure that won't happen, you can remove the line that starts with "True". But it shouldn't hurt to keep it either.
More info: Pie Chart Techniques (look for Custom Coloring chapter)