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
Related
Using Visual Studio 2017 (SSDT), I have a tablix where I would like to use an expression to set the background color/fill. I would like the cells to fill gray where the:
2019 Metal is Silver and 2020 Metal is Bronze, or
2019 Metal is Gold and 2020 Metal is Bronze, or
2019 Metal is Gold and 2020 Metal is Silver.
Visually, like this:
The data set populating the tablix is:
(I added custom "Is Null" code to display zeros instead.)
I've been trying IIF statement logic but have been unable to get my desired results.
The design of the tablix is:
I'm trying to set the Fill BackgroundColor on the textbox here with an expression:
...using something like:
=IIF(
Fields!METAL_YEAR_2020.Value="Bronze" AND
(Fields!METAL_YEAR_2019.Value = "Silver" OR Fields!METAL_YEAR_2019.Value = "Gold")
, "Gray"
, "Transparent"
)
If I leave out the OR condition I can fill one intended cell, but I don't know how to account for the three cells.
So, this code below sets one cell but can I nest or SWITCH to set the three cells I want?
= IIF(
(
(Fields!METAL_YEAR_2019.Value = "Silver" and Fields!METAL_YEAR_2020.Value = "Bronze")
OR (Fields!METAL_YEAR_2019.Value = "Gold" and Fields!METAL_YEAR_2020.Value = "Bronze")
OR (Fields!METAL_YEAR_2019.Value = "Gold" and Fields!METAL_YEAR_2020.Value = "Silver")
)
, "Gray", "White")
since there is no data where you get the null values (not only the integer value is absent, but all values, you have to refer to the group value, which is in the textbox)
= iif(
(cstr(ReportItems!Metal_2019.Value) = "Silver" AND cstr(ReportItems!Metal_2020.Value) = "Bronze") OR
(cstr(ReportItems!Metal_2019.Value) = "Gold" AND (cstr(ReportItems!Metal_2020.Value) = "Silver" OR cstr(ReportItems!Metal_2020.Value) = "Bronze")),
"Gray","Transparent")
found at
I have the following expression:
=CountDistinct(IIf((Fields!txtGrade.Value = "*")
And (Fields!txtCurrentSubjectName.Value = "3D Design"),
Fields!intGradeTransposeValue.Value, Nothing))
There are 5 different txtGrade.Value in all - *, 1, 2, 3, 4 not every subject will have a grade. In the columns that have no values the expression is returning back a 0 - is there anyway I can just get it to show a blank cell with no number in it at all. This is what it currently outputs:
There are a couple of options you can use here. First, you could simply wrap the entire expression in an IIF that replaces the zeros with nothing.
=IIF(CountDistinct(IIf((Fields!txtGrade.Value = "*")
And (Fields!txtCurrentSubjectName.Value = "3D Design"),
Fields!intGradeTransposeValue.Value, Nothing)) = 0, "",
(CountDistinct(IIf((Fields!txtGrade.Value = "*")
And (Fields!txtCurrentSubjectName.Value = "3D Design"),
Fields!intGradeTransposeValue.Value, Nothing))))
The second option would be to set the text box properties to show zeros as a blank as shown in this image:
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 data in an SSRS report that groups and provides percentages. I need to change the font color for the percentages and I can't figure out how to create the expression.
Currently I obtain the percentage with this formula:
Sum(Fields!Time_Msg.Value)/Count(Fields!Driver.Value)
The Time_Msg field is obtained from SQL. I want the font expression to be the greater of three colors using this formula:
IIF(Fields!Time_Msg.Value = 1, "green",
IIF(Fields!Time_Msg.Value = 0
And Fields!Time.Value > Fields!TimeB.Value, "red", "yellow"))
So essentially if the record is on time the font will be green, if the record is late then red and early then yellow.
But what do you do when providing grouping sums? If from all the records the greatest value is green, then the font for the grouping sum should be green, etc.
Sorry for formatting as I'm new to this forum..
go to Textbox properties-> Font -> Color and type an expression like this
Instead of using IIF please try to use Switch statement.
= switch(Fields!Time_Msg.Value = 1, "green",
Fields!Time_Msg.Value = 0
And Fields!Time.Value > Fields!TimeB.Value, "red")
Note: Put your condition in switch statement.
Let me know if this works
You can use custom code in your project
Function SetColor(ByVal Value As Integer) As String
Dim Ret as string
Dim doubleVal As Double
Ret = "Blue"
Dim Val As Double
doubleVal = System.Convert.ToDouble(Value)
if Value >= .86 then
Ret = "OliveDrab"
ElseIf Value <=.86 then
Ret = "IndianRed"
end if
End Function
assign whatever numbers you want to whichever colours you are using (I'm using greater or less than 86%) and set the font colour expression to =Code.SetColor(Me.Value)
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)