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.
Related
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.
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 two fields for current version number and previous version number in a form. What I want to do is when I enter the current version number (which is written like this 18.04.15), the previous version number on the next text box to automatically fill itself with 18.04.14.
I tried:
=[txtCurrentVersion]-1 in the control source, but obviously because I'm not decrementing by one, it didn't work.
Would appreciate some guidance, thanks :)
Below code splits the text based on dot and subracts one from last item.
Private Sub txtCurrentVersion_AfterUpdate()
If Nz(Me.txtCurrentVersion, "") <> "" Then
Me.txtPrevVersion.Value = Split(Me.txtCurrentVersion, ".")(0) & "." & Split(Me.txtCurrentVersion, ".")(1) & "." & Split(Me.txtCurrentVersion, ".")(2) - 1
End If
End Sub
I would suggest creating a function where you give the function 3 parameters, the 1st is the current version number string, the 2nd is the version number level (0 for major number, 1 for subversion number and 2 for minor version number) and the value to increase or decrease.
for example:
Function ModifyVersion(VersionNumber, NumberLevel, Number)
If VersionNumber <> "" AND NumberLevel >= 0 AND NumberLevel < 3 Then
dim VersionArray
VersionArray = Split(VersionNumber, ".")
Select Case NumberLevel
Case 0
VersionArray(0) = VersionArray(0) + Number
Case 1
VersionArray(1) = VersionArray(1) + Number
Case 2
VersionArray(2) = VersionArray(2) + Number
End Select
ModifyVersion = VersionArray(0) & "." & VersionArray(1) & "." & VersionArray(2)
End If
End Function
Then to decrease one from the minor version number use:
VersionNumber = [txtCurrentVersion]
Dim UpdateVersion
UpdateVersion = ModifyVersion(VersionNumber, 2, -1)
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"
)
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"