Conditional formatting for a cell in a Table in my report - reportbuilder

I’m trying to use conditional formatting for a fill color in a table cell in a report. The statement I’m using is:
IIF (GETDATE() >= (DATEADD(day, 25, B6CONDIT.B1_CON_ISS_DD)) AND (GETDATE () <= (DATEADD(day, 30, B6CONDIT.B1_CON_ISS_DD)), "Yellow", "White"))
I'm getting an error when I try to apply it to my table that says:
"IIF (GETDATE() >= (DATEADD(day, 25, B6CONDIT.B1_CON_ISS_DD)) AND (GETDATE () <= (DATEADD(day, 30, B6CONDIT.B1_CON_ISS_DD)), "Yellow", "White")) is not valid color."
What am I doing wrong?
Thanks!
Phil R
I've made sure that my parentheses are matched and I know that Yellow and White are valid colors.

Related

SSRS - Conditional formatting not getting applied?

I have the following expression to apply background colour to a text box but only the red colour is getting applied when that condition is true. All the other conditions are showing up as white? For example when the first condition is true when the report renders, the background colour is white instead of green?
=IIF(Round(SUM(CInt(Fields!TotalAchieved.Value) * 7.14)) >= 86, "Green",
IIF(Round(SUM(CInt(Fields!TotalAchieved.Value) * 7.14)) >= 79 AND
Round(SUM(CInt(Fields!TotalAchieved.Value) * 7.14)) <= 85, "Light Green",
IIF(Round(SUM(CInt(Fields!TotalAchieved.Value) * 7.14)) >= 64 AND
Round(SUM(CInt(Fields!TotalAchieved.Value) * 7.14)) <= 78, "Yellow", "Red" )))
It would seem that your SUM(CINT(Fields!TotalAchieved.Value) * 7.14) calculation is not giving you the results you expect . The first thing I would do is add a column that shows this value to make sure that it's gives you what you expect.
Once you have that correct then I would also suggest that you use a SWITCH statement rather than nested IIFs, they are much easier to read/debug.
You expression would be
=SWITCH(
Round(SUM(CInt(Fields!TotalAchieved.Value) * 7.14)) >= 86, "Green",
Round(SUM(CInt(Fields!TotalAchieved.Value) * 7.14)) >= 79, "LightGreen",
Round(SUM(CInt(Fields!TotalAchieved.Value) * 7.14)) >= 64, "Yellow",
TRUE, "Red"
)
This way you don't need to check for ranges as, for example, if the value was 75, the 1st expression fails but the second one is true so SWITCH will stop at that point and not evaluate the rest, if all fail then the final TRUE will act like an else.

SSRS =Switch not altering text

Can anyone please help explain why when the first switch value is 0 it will change to red, but when it is the text value "Expired" (altered with a CASE WHEN in the query) the text remains black.
This does not work:
=Switch(Fields!Days_Until_Expiry.Value = "Expired", "Red"
, Fields!Days_Until_Expiry.Value > 1 AND Fields!Days_Until_Expiry.Value < 90, "Orange"
, Fields!Days_Until_Expiry.Value > 90, "Green")
, CASE
WHEN DATEDIFF(d, c.Date_Expiration, SYSDATETIME()) > 0
THEN 'Expired'
[...]
This does work:
=Switch(Fields!Days_Until_Expiry.Value = 0, "Red"
, Fields!Days_Until_Expiry.Value > 1 AND Fields!Days_Until_Expiry.Value < 90, "Orange"
, Fields!Days_Until_Expiry.Value > 90, "Green")
, CASE
WHEN DATEDIFF(d, c.Date_Expiration, SYSDATETIME()) > 0
THEN 0
[...]
This is going to be a simple explanation I haven't been able to find, isn't it...
[EDIT]:
Seems the problem is in the query.
, CASE
WHEN DATEDIFF(d, c.Date_Expiration, SYSDATETIME()) > 0
THEN 'Expired'
ELSE ABS(DATEDIFF(d, c.Date_Expiration, SYSDATETIME()))
END AS Days_Until_Expiry
How can I make this query work and have SSRS pick up both the returned int values and the text string?
From what I see the switch statement is unable to determine whether Days_Until_Expiry is returning a string or an int. Ideally (depending on your version of SSRS) you should have seen a #Error instead of just a blank textbox.
I tried to recreate this (in SSRS 2008R2) but I ended up seeing the #Error in the textbox with an error message in my output window:
The Value expression for the textrun ‘Textbox3.Paragraphs[0].TextRuns[0]’ contains an error: Input string was not in a correct format.
When you updated your CASE statement so that Days_Until_Expiry always returns an int the Switch was able to evaluate all conditions correctly.
[Edit]: If you are trying to get string and int values into SSRS so that you can further evaluate the status to be "Red", "Orange" or "Green", you can combine the CASE and SWITCH logic into to the CASE statement as follows:
CASE
WHEN DATEDIFF(d, c.Date_Expiration, SYSDATETIME()) > 0
THEN 'Red'
WHEN ABS(DATEDIFF(d, c.Date_Expiration, SYSDATETIME())) > 1 AND ABS(DATEDIFF(d, c.Date_Expiration, SYSDATETIME())) < 90
THEN 'Orange'
ELSE 'Green'
END AS Days_Until_Expiry
You can then directly display Days_Until_Expiry without using any SWITCH statement. Let me know if I am missing something.

SSRS 2008R2: How we can hide X-axis label in line chart?

I am new in SSRS world.
I have set the X-axis label interval '1' and Interval Type 'day'. It is working properly. Now I want to hide the all label Except the 1st, 15th,31th Date of every month. Is it possible to set the expression in hide properties for X-axis?
Can anyone help me regarding that?
EDIT #2
Open the Category Group properties - there you will have the option to define expression to the labal. Then use the following expression:
Switch(Day(Fields!SAMPLE_DATE.Value) = 31 , "31", Day(Fields!SAMPLE_DATE.Value)> 1 AND Day(Fields!SAMPLE_DATE.Value) < 14 , " ", Day(Fields!SAMPLE_DATE.Value) = 15 , "15", Day(Fields!SAMPLE_DATE.Value) > 15 AND Day(Fields!SAMPLE_DATE.Value) < 30, " ", Day(Fields!SAMPLE_DATE.Value) = 30 , "30")

Range inside switch case statement in Coffeescript

I am using Handlebar in my Rails 3.2 jquery mobile application.
I am trying to write a switch case statement inside a Coffeescript method like
Handlebars.registerHelper 'status', (blog) ->
switch(parseInt(blog.status))
when [0..20]
status = "active"
when [20..40]
status = "Moderately Active"
when [40..60]
status = "Very Active"
when [60..100]
status = "Hyper Active"
return status
I am not getting any result . How to use range in when . Please suggest
Your switch won't work as Cygal notes in the comments (i.e. see issue 1383). A switch is just a glorified if(a == b) construct and you need to be able to say things like:
a = [1,2,3]
switch a
...
and have it work when you switch on an array. The CoffeeScript designers thought adding a (fragile) special case to handle arrays (which is all [a..b] is) specially wasn't worth it.
You can do it with an if:
Handlebars.registerHelper 'status', (blog) ->
status = parseInt(blog.status, 10)
if 0 <= status <= 20
'Active'
else if 20 < status <= 40
'Moderately Active'
else if 40 < status <= 60
'Very Active'
else if 60 < status <= 100
'Hyper Active'
else
# You need to figure out what to say here
Or with short circuiting returns like this:
Handlebars.registerHelper 'status', (blog) ->
status = parseInt(blog.status, 10)
return 'Something...' if status <= 0
return 'Active' if status <= 20
return 'Moderately Active' if status <= 40
return 'Very Active' if status <= 60
return 'Hyper Active' if status <= 100
return 'Something else' # This return isn't necessary but I like the symmetry
Note that you have three special cases that you need to add strings for:
status < 0.
status > 100.
status is NaN. This case would usually fall under the final "it isn't less than or equal to 100" branch since NaN => n and NaN <= n are both false for all n.
Yes, you're absolutely certain that the status will always fall within the assumed range. On the other hand, the impossible happens all the time software (hence the comp.risks mailing list) and there's no good reason to leave holes that are so easily filled.
Also note the addition of the radix argument to the parseInt call, you wouldn't want a leading zero to make a mess of things. Yes, the radix argument is optional but it really shouldn't be and your fingers should automatically add the , 10 to every parseInt call you make.
Adding a tiny bit to mu is too short's answer, you can transform its second code snippet into a switch expression:
Handlebars.registerHelper 'status', (blog) ->
status = parseInt(blog.status, 10)
switch
when status <= 0 then 'Something...'
when status <= 20 then 'Active'
when status <= 40 then 'Moderately Active'
when status <= 60 then 'Very Active'
when status <= 100 then 'Hyper Active'
else 'Something else'
This is basically equivalent to doing a switch (true) in JavaScript (though the CS compiler will generate a switch (false) statement with the negated conditions to ensure boolean results from the expressions... i think).
And the reason why the switch over ranges doesn't work is that ranges literals in CS represent plain old JS arrays (though the compiler will do some optimization tricks when doing something like for i in [1..something]), so when they are found inside a switch they are treated just like normal array values:
// Generated JS for question's CS code:
switch (parseInt(blog.status)) {
case [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]:
status = "active";
break;
case [20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40]:
status = "Moderately Active";
break;
case [40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60]:
status = "Very Active";
break;
case (function() {
_results = [];
for (_i = 60; _i <= 100; _i++){ _results.push(_i); }
return _results;
}).apply(this):
status = "Hyper Active";
}
The value inside the switch statement is basically compared to each case value using ===, which only works for primitives, not for arrays (and even if it worked for arrays, it would be testing array equality, not if the switched value is contained in the caseed arrays).

Correct syntax for SSRS Nested IIf needed

I have the following expression. Can somebody tell me why it is printing 0.
=IIF(Parameters!StartMonth.Value <= 1 And Parameters!EndMonth.Value >= 1, ReportItems!txtTotal1.Value,
IIF(Parameters!StartMonth.Value <= 2 And Parameters!EndMonth.Value >= 2, ReportItems!txtTotal2.Value,
IIF(Parameters!StartMonth.Value <= 3 And Parameters!EndMonth.Value >= 3, ReportItems!txtTotal3.Value, 0)))
Thanks
It looks to me like if Parameters!StartMonth.Value is > 3, your statement will return 0.