SSRS - show field in expression based on where clause? - reporting-services

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.

Related

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.

SQL Server Reporting Services Expression BackgroundColour Based On DateDiff

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"
)

Building Selection Criteria to filter record set

I use a series of if-then statements to build a selection criteria to filter records. There are several unbounded combo boxes and now I want to add checkboxes (if they are check to the criteria.) Here is the code that I am having a problem with (doesn't error or give a result - just back record):
This Section Processes checkbox minseries for true
If chkMiniSeries = True Then 'checkbox is checked'
SelCrit = SelCrit & xAnd & MiniSeries_TV = True 'add checkbox to SelCrit'
xAnd = " And "
End If
The bold indicates where i am looking for help!
Thanks for any support
You are building a filter string, so you need to concatenate a string:
SelCrit = SelCrit & xAnd & "MiniSeries_TV = True"

format lookupset expression

In Report Builder, I have an expression using the lookupset function that pulls back either nothing, a date and description, or several dates and several descriptions. The data it is pulling is correct. I have searched this forum and MSDN. Using what I've found in both places, I have tweaked my expression to the following.
My expression:
=Join(Lookupset(Fields!ProjectName.Value,
Fields!ProjectNames.Value,
Fields!TaskBaseline0FinishDate.Value & " - " & Fields!TaskName.Value,
"DsActivitiesCompleted"))
However, when this is displayed it doesn't have a carriage return, it just puts one after another after another. Example Below:
08/05/2015 – Milestone: Kickoff meeting Complete 08/18/2015 – Milestone: PMT Test Planning Complete 08/26/2015 – Milestone: Set CCD Date 08/26/2015 – Sprint 0 Complete 09/18/2015 – Milestone: Wave 1 Complete 09/28/2015 - Milestone: Wave 2 Complete
What I want it to look like is below. If possible I would like to have bullet points in front of each line as well.
My question is how do I get it in the format above?
Thanks,
MM
You have missed the final (optional) argument of JOIN which states which character you want to use to join your string together. Changing your expression tyo use vbCrLf (the VB new line code) as follows
=Join(Lookupset(Fields!ProjectName.Value,
Fields!ProjectNames.Value,
Fields!TaskBaseline0FinishDate.Value & " - " & Fields!TaskName.Value,
"DsActivitiesCompleted"),
vbCrLf)
Gives this output
Update
Use the below to use Chr(183) as a bullet character for each new line as well
=" " + Chr(183) + " " +
Join(Lookupset(Fields!ProjectName.Value,
Fields!ProjectNames.Value,
Fields!TaskBaseline0FinishDate.Value & " - " & Fields!TaskName.Value,
"DsActivitiesCompleted"),
vbCrLf + " " + Chr(183) + " ")

Filter for Text with spaces

Using Microsoft Access I want to set a filter for records which include spaces. I tried double escaping by using '""' to no avail.
I have a table like so:
ID Title
1 Green
2 Blue Yacht
3 Yellow
and a form just displaying these records. When I now set the filter:
Form.Filter = "TestTable.Title LIKE '*Yellow*'"
it works like a charm. But when trying to filter for "Blue Yacht"
Form.Filter = "TestTable.Title LIKE '*Blue Yacht*'"
I get an empty result. Filtering for just Blue works like it is supposed to. Somehow Access doesn't like the spaces in the filter. How can I filter for e.g. "Blue " or "Blue Yacht"?
That's very strange behaviour, it should work fine as is, you could try using the Chr code instead of the space:
Form.Filter = "TestTable.Title LIKE '*Blue" & Chr(32) & "Yacht*'"
I stumbled upon this old thread while searching a solution for the same problem. I found none so far. I wonder if this is a bug on Access or what.
So, this is my case, I tried both filters below. I was working to filter and populate a Datasheet subform. Filters are in Combo Box: Citrate, Paxgene, Sodium Herapin.
Dim sTType as string
...
...
1. sTType = "[Tube Type] LIKE '" & Me.txtTubeType & "*'"
2. sTType = "[Tube Type] ='" & Me.txtTubeType & "'"
...
me.Filter = sTType
When Sodium Herapin is selected and applied as filter , the filter comes up with nothing, while I've no problem with the other word filters.
Sol.: I inserted this code way up
me.txtTubeType = iif(InStr(Trim(Me.txtTubeType), "Sod") > 0, "Sodium*", me.txtTubeType)
...
...
sTType = "[Tube Type] LIKE '" & Me.txtTubeType & "'"
me.Filter = sTType
The work around is kind of crude but it worked for my situation.
Cheers!