SQL Server Reporting Services Expression BackgroundColour Based On DateDiff - reporting-services

I'm trying to use conditional formatting in SQL Server Reporting Services to change the colour of a row if a value is the same as today's date or not. The column contains the date in the format 13/07/2018. I have also set the field to be in date format (31/01/2000) within place-holder properties.
My expression however is not working
=switch(DateDiff("d", Fields!LastSuccessfulBackupTime00.Value,Format(Now(),"dd/MM/yyyy")) = 0, "Green",DateDiff("d", Fields!LastSuccessfulBackupTime00.Value,Format(Now(), "dd/MM/yyyy")) = 1, "Yellow",DateDiff("d", Fields!LastSuccessfulBackupTime00.Value,Format(Now(), "dd/MM/yyyy")) >= 2, "Red")
The exception that is being thrown is
Argument matching parameter 'DayOfWeek' narrows from 'String' to 'Mcrosoft.VisualBasic.FirstDayOfWeek'
Which is strange because I'm just doing simple datediff calculation to count the number of days between two dates.
Can anyone suggest how to fix this ? Google just says to turn off strict compilation something which I can't find in SQLRS

Try the expression below (expression 1)
=switch(
DateDiff("d", Cdate(Fields!LastSuccessfulBackupTime00.Value),Today()) = 0, "Green"
,DateDiff("d", Cdate(Fields!LastSuccessfulBackupTime00.Value),Today()) = 1, "Yellow"
,DateDiff("d", Cdate(Fields!LastSuccessfulBackupTime00.Value), Today()) >= 2, "Red"
)
Also because Cdate is regional setting dependant you could use Split to create a valid date format for datediff (expression2)
=switch(
DateDiff("d", Fields!LastSuccessfulBackupTime00.Value.Split("/")(2) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(1) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(0),Today()) = 0, "Green"
,DateDiff("d", Fields!LastSuccessfulBackupTime00.Value.Split("/")(2) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(1) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(0),Today()) = 1, "Yellow"
,DateDiff("d", Fields!LastSuccessfulBackupTime00.Value.Split("/")(2) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(1) & "-" & Fields!LastSuccessfulBackupTime00.Value.Split("/")(0),Today()) >= 2, "Red"
)

Related

SSRS Conditional Formatting with start date and end date being on the current day

I am trying to implement conditional formatting where the background fill changes when the start date and end date is both the current day but it is defeating me.
Here is what I have:
=IIf(Fields!Adata.Value = "Ball","Yellow",nothing)
=IIF(Fields!Bdata.Value = "Sign","Yellow",nothing)
=IIF(Format(END_DATE.Value, "yyyyMMdd") = Format(Today(), "yyyyMMdd"),
"Yellow", nothing)
=IIF(Format(START_DATE.Value, "yyyyMMdd") = Format(Today(), "yyyyMMdd"),
"Yellow", Nothing)
How do I get these to work as one expression versus 4 separate expressions, having the 2 date expressions work together where they only trigger when the start date and end date are both equal to the current day.
Just missing an AND, though as noted by Alan END_DATE and START_DATE look like they need something in front of them; Field!, Parameters! etc.:
=IIF(Fields!Adata.Value = "Ball","Yellow", IIF(Fields!Bdata.Value = "Sign","Yellow", IIF(((Format(END_DATE.Value, "yyyyMMdd") = Format(Today(), "yyyyMMdd")) AND ((Format(START_DATE.Value, "yyyyMMdd") = Format(Today(), "yyyyMMdd")))), "Yellow", nothing))))

SSRS - show field in expression based on where clause?

I have a data table that looks like the below. This shows the top 3 subcallcategories based on the amount of calls. The "order" column is a row number that shows which order the subcallcategory was in based on the calls.
I am trying to write some DAX in SSRS which displays the following
Anxiety was the most common counselling call, followed by Work Related
Stress and Bereavement
I have written the below code however it doesn't seem to be picking up the last 2 categories? Anyone have any ideas what I am doing wrong?
=IIf(Fields!Order.Value = "1" and Fields!Category.Value = "Counselling", Fields!SubCallCategory.Value, "") &
" was the most common counselling call, followed by " &
IIf(Fields!Order.Value = "2" and Fields!Category.Value = "Counselling", Fields!SubCallCategory.Value, "") &
" and " & IIf(Fields!Order.Value = "3" and Fields!Category.Value = "Counselling", Fields!SubCallCategory.Value, "")
Below is my current output
As Alan mentioned, your expression is just looking at a single row of data.
You would need to put this expression in a table with Grouping by Category.
Then you would look for the ones in your ORDER and use that Sub Cat value. I use MAX and NULL to get matching values like
=MAX(IIf(Fields!Order.Value = 1, Fields!SubCallCategory.Value, NOTHING)) &
" was the most common " & Fields!Category.Value & " call, followed by " &
MAX(IIf(Fields!Order.Value = 2, Fields!SubCallCategory.Value, NOTHING)) &
" and " & MAX(IIf(Fields!Order.Value = 3, Fields!SubCallCategory.Value, NOTHING))
The MAX will get the SubCat value over NOTHING (SSRS for NULL) for the ones in the right ORDER.
This would give one line for Counselling and one for Legal.
You could also add the totals in with
MAX(IIf(Fields!Order.Value = 1, Fields!Calls.Value, 0))
I assume your ORDER field is an INTEGER and doesn't need the quotes.

SSRS - Concatenate Multiple Parameter Values in a Text Box

I have an SSRS report with several parameters the user selects at runtime. One of the parameters allows multi-select. I'm using the values to populate a text box and am having a problem using the parameter values when multiples are selected. Below is when the user selects one value and this works:
=Switch(Parameters!ID.Value(0) = 5, "Location 1", Parameters!ID.Value(0) = 9, "Location 2") & " Status Report"
I have another case, though. Since it's multi-select, if the parameter carries values of 5 and 9, I want to have have it say "Location 1 and Location 2" & " Status Report"
I'm not sure how to accomplish that.
I tried:
=Switch(Parameters!ID.Value(0) = 5, "Location 1", Parameters!ID.Value(0) = 9, "Location 2", **Parameters!ID.Value(0) = 5 AndAlso Parameters!ID.Value(0) = 9, "Location 1 and Location 2"**) & " Status Report"
Thoughts?
Assuming your ID parameter either
Take its available values from a query or
Has its available values set manually
You should therefore have two properties available in your parameter. Its value (the bit that is actually passed to queries/filters etc) and a label (the bit you normally see as a user).
Lets say then that you have 3 IDs in your parameter list like
Value Label
5 Location 1
9 Location 2
10 Some other location
Then all you need to do is reference the labels of the parameters collections in your expression like this.
= JOIN(Parameters!ID.Label, " and ") & " Status Report."
That's it.
What I do when trying to find a value in a multi-value parameter is JOIN all the values together into a string.
"|" & JOIN(Parameters!ID.Value,"|") & "|"
If parameter values 1, 2, and 3 are selected, the string would be |1|2|3|. The pipes are added so 1 isn't found when 11 is selected.
If you want to check for a certain value, use the INSTR function with your value enclosed in Pipes. INSTR will return 0 if not found and the character position if it is found.
This will search for a 5 from the parameter string above:
INSTR("|" & JOIN(Parameters!ID.Value,"|") & "|", "|5|")
So your expression would end up like
=Switch(INSTR("|" & JOIN(Parameters!ID.Value,"|") & "|", "|5|") > 0 AndAlso INSTR("|" & JOIN(Parameters!ID.Value,"|") & "|", "|9|") > 0, "Location 1 and Location 2",
INSTR("|" & JOIN(Parameters!ID.Value,"|") & "|", "|5|") > 0, "Location 1",
INSTR("|" & JOIN(Parameters!ID.Value,"|") & "|", "|9|") > 0, "Location 2",
1 = 1, "Locations " & JOIN(Parameters!ID.Value,", ")) &
" Status Report"
I moved your criteria with AND to the first position because a SWITCH will choose the first one and never get to your 3rd one unless neither 5 nor 9 was selected. I also added the 1 = 1 as a fallout if neither 5 not 9 are selected.
I have used the following and it worked for me:
=CStr(Parameters!Month.Label) &", " &CStr(Parameters!Year.Label)
You need to convert numbers to strings using CStr, so that you can add other characters like comma.

Prevent "0" in CountDistinct in SSRS

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:

SSRS - nvarchar custom formatting

I have a nvarchar cell with some number as is : 12345678, and I would format it like this : 12-345-678. But I'm unable to find the right expression...
Should I do this in TSQL before inserting it in the report ?
I'm using SSRS 2008
You can do this in either T-SQL or an SSRS expression.
T-SQL:
declare #value nvarchar(8);
select #value = '12345678';
select formattedValue = left(#value, 2)
+ '-' + substring(#value, 3, 3)
+ '-' + right(#value, 3);
SSRS expression:
=Left(Fields!value.Value, 2)
& "-" & Mid(Fields!value.Value, 3, 3)
& "-" & Right(Fields!value.Value, 3)
This assumes a fixed length text.
It's really up to you which is better - I suppose one consideration would be to keep the formatting at the presentation layer, i.e. SSRS, so that's probably the way I would go. But nothing stopping you using either option.