Populating multiple values in rdlc reporting - reporting-services

I am using rdlc report, i have a column in database which i want to display in the report.
vehicleDamageArea=1,2,3
In the report I need to mark the placeholders with these values.
=iif((Fields!vehicleDamageArea.Value="3"),Chr(253),Chr(168)) like this.
But as we know,it will check the whole value 1,2,3="3" not the splitted values.
Any suggestion to check by splitting the vehicleDamageArea parameter.
I made it to work as below
Public Shared Function CheckValue(ByVal InString As String,ByVal input as String) As Char
Dim output As String = String.Empty
Dim Parts() As String = InString.ToString().Split(",")
For i As Integer = 0 To Parts.Length - 1
If Parts(i) = input Then
output = Chr(0120)
Exit For
Else
output = Chr(0111)
End If
Next i
Return output
End Function

You can get the individual values using the split function in reporting services. It returns a zero-based string array, so for your example you need
=Split(First(Fields!ID.Value),",")(2)

You should make a function that accept a comma separated expression, than process this string and return a Boolean, then call this function as for boolean value.

Related

SSRS How to feed a certain value of a Dataset Field to a Variable in a Custom Code

I have a report which contains conditional formatting. The colour value is feeding through Variables in a Custom Code on the report as below, Dim vRed as String ="#FF0000" Dim vGreen as String ="#008000" and the coding continues..
Now the problem is, we have many reports and if we wanted to change the colour we have to change each report. Therefore, we created a Config Table with two columns. One for ColourName and another for ColourCode.
Now I wanted to feed "red" ColourCode to vRed in the Custom Code. Can someone help me how to do this please.
If you just need to set a variable, you can create a function with the variable and value to set it.
Public Function SetVariableValue(varName as Microsoft.ReportingServices.ReportProcessing.OnDemandReportObjectModel.Variable, varValue as String)
varName.Value = varValue
End Function
Then you need to call it like
=CODE.SetVariableValue(Variables!CCColors.Value, FIRST(Fields!Color.Value, "Dataset1"))
See SSRS reference report variable from report function
Let's assume you have a bit of code like this.
Public Function myFunction (someParameter AS Integer, someOtherParameter as String) AS String
Dim vRed as String = "#FF0000"
Dim vGreen as String = "#008000"
Dim vBlue as String = "#0000FF"
' some code here
End Function
And you call your code with something like
=Code.myFunction(Fields!SomeInt.Value, Fields!SomeText.Value)
You will need to create a dataset called dsColours containing your colour values, as it's a very small table, I would pivot this to make it easier to reference in the report.
SELECT DISTINCT
(SELECT ColourCode FROM myConfigTable WHERE ColourName = 'Red') AS Red,
(SELECT ColourCode FROM myConfigTable WHERE ColourName = 'Green') AS Green,
(SELECT ColourCode FROM myConfigTable WHERE ColourName = 'Blue') AS Blue
FROM myConfigTable
Now change your function to look like this.
Public Function myFunction (someParameter AS Integer, someOtherParameter as String, vRed as String, vGreen as String, vBlue as String) AS String
' some code here
End Function
and call your new function like this
=Code.myFunction(Fields!SomeInt.Value, Fields!SomeText.Value,
FIRST(Fields!vRed.Value, "dsColours"),
FIRST(Fields!vGreen.Value, "dsColours"),
FIRST(Fields!vBlue.Value, "dsColours")
)

Display the non selected parameter in SSRS

In case of Multi-valued parameters,we usually use join function to display the selected values into a Text-box.But what if I wanted Show only the non selected parameters?IE If there are 10 values in the drop down list of a parameter and I selected the first 5 and wanted to display only the remaining 5 parameter instead of the first 5.What do i do?
I have created a multivalue parameter with the name Param which has had its labels and values set like so:
Label Value
====== =====
Label1 1
Label2 2
Label3 3
Label4 4
Label5 5
I then created the following code in the Report Properties --> Code menu:
'Global array objects to hold the total and selected values
Private Dim parameterList() AS string
Private Dim selectedParameters() AS string
'populates the list of all parameters using split and returns the input string
Public Function SetParameterList(nextParameter as String) AS String
parameterList = Split(nextParameter ,",")
Return nextParameter
End Function
'populates the list of selected parameters using split and returns the input string
Public Function SetSelectedParameters(delimitedParameters as String) AS String
selectedParameters = Split(delimitedParameters,",")
Return delimitedParameters
End Function
'Returns the not selected parameters
Public Function GetNotSelectedParameters() AS String
Dim notSelected As String
Dim i as Integer
Dim x as Integer
'Loop through each value in the all parameters array...
For i = 0 to parameterList.GetUpperBound(0)
'...for each one of those values check it against the selected parameters
For x = 0 to selectedParameters.GetUpperBound(0)
'Where there is a match, set the all parameters value to a string unlikely to be a genuine parameter value
IF parameterList(i) = selectedParameters(x) Then
parameterList(i) = "!*!"
End IF
Next
Next
'Join the all parameters array back into a string
notSelected = Join(parameterList, ", ")
'Remove the !*! values added earlier from the middle and the end of the string
notSelected = Replace(notSelected, "!*!, ", "")
notSelected = Replace(notSelected, ", !*!", "")
Return notSelected
End Function
To use this code I created 3 textboxes with the following expressions:
=Code.SetParameterList(Join(LookUpSet(1,1,Fields!ParamLabel.Value,"DataSet1"),","))
=Code.SetSelectedParameters(Join(Parameters!Param.Label, ","))
=Code.GetNotSelectedParameters()
Note: to hide the output of any of these textboxes, you could set the function return value to be "".
I imagine my code could be improved upon significantly, but this gets the job done and should at least point you in the right direction.
First create a multivalued parameter ("param1"), with available values ranging from 1 to 10.
Then create a query (query1), which returns the parameters from 1 to 10 filtering out the
selected values from "param1" -> where query1.col NOT IN (#param1)
Then create another multivalued parameter("param2"), set a default value (get values from a query) point to "query1" to fill in the unselected values
use a text box with the following code "=Join(Parameters!param1.Value,",")"
To make query1 you can use unions.
You will get back the values not selected,

Multi-value parameters in ssrs

I have a multi-value parameter. how I get one by one values from this parameter.
value=new_index and label=new_french
and want to insert these values into these labels
You can access the individually selected multi-value parameters by their index (the index is zero-based). So if you want the first selected parameter value (for example, to put it into a label), you can address it like so:
=Parameters!MyParameter.Value(0)
You could access them all using custom code:
Function DoSomething (ByVal parameter As Parameter) AS String
Dim Result As String
If parameter.IsMultiValue then
For i As integer = 0 To parameter.Count-1
Result = Result + CStr(parameter.Value(i)) + ", "
Next
Result = Left(Result, Result.Length - 2)
Else
Result = CStr(parameter.Value)
End If
Return Result
End Function
then use this expression to access the result:
=Code.DoSomething(Parameters!MyParameter)
Note that you are passing the parameter object here, not the Value property. We access the Value property in the custom code function.

NOT IN in SSRS TextBox

How can I write NOT IN in TextBox expression?
I must check if some field value not belong to some list of strings, and then do some work.
Example:
Iif(SomeField.Value NOT IN ('Text1', 'Text2'), DoSomething, nothing)
I wrote code like this and got error when previewing report, and error was :
Overload resolution failed because no accessible 'Iif' accepts this number of type arguments
How can I do this stuff?
Try this small piece of custom code that accepts a string array. Just paste it into the report code section of the report..
Public Shared Function ValueExists(ByVal arr() as string, checkVal as string)
Dim i As Long
For i = LBound(arr) To UBound(arr)
If arr(i) = checkVal Then
return true
Exit Function
End If
Next i
return false
End Function
Usage would involve splitting the string into an array using the Split function
like so:
=iif(Code.ValueExists(Split("Your,comma,separated,string,in,here",","),"StringYouWantToFind")
,"Your value exists"
,"your value does not exist")
You can simply write the code like this:
Iif(SomeField.Value <> 'Text1' AND Field.Value <> 'Text2' , DoSomething, nothing)
I got this one in one report:
=iif(join(Parameters!Parameter1.Value,",") like "*" & Fields!Field1.Value & "*","Color1","Color2")
This instruction helps me to determine the fill colour of a cell inside a tablix, where:
Parameter1 is a multivalue parameter.
"Join" lets me have a string with all selected values from a multivalue parameter, eg. "value1,value2,value3,value4"
Field1 is the field that contains the values filtered by Parameter1
Color1 is the color if the value of the cell is included in the selection of parameter
else Color2
works well

SSIS Convert Blank or other values to Zeros

After applying the unpivot procedure, I have an Amount column that has blanks and other characters ( like "-"). I would like to convert those non-numberic values to zero. I use replace procedure but it only converts one at the time.
Also, I tried to use the following script
/**
Public Overrides Sub Input()_ProcessInputRows(ByVal Row As Input()Buffer)
If Row.ColumnName_IsNull = False Or Row.ColumnName = "" Then
Dim pattern As String = String.Empty
Dim r As Regex = Nothing
pattern = "[^0-9]"
r = New Regex(pattern, RegexOptions.Compiled)
Row.ColumnName = Regex.Replace(Row.ColumnName, pattern, "")
End If
End Sub
**/
but i'm getting error.I don't much about script so maybe I placed in the wrong place. The bottom line is that I need to convert those non-numberic values.
Thank you in advance for your help.
I generally look at regular expressions as a great way to introduce another problem into an existing one.
What I did to simulate your problem was to write a select statement that added 5 rows. 2 with valid numbers, the rest were an empty string, string with spaces and one with a hyphen.
I then wired it up to a Script Component and set the column as read/write
The script I used is as follows. I verified there was a value there and if so, I attempted to convert the value to an integer. If that failed, then I assigned it zero. VB is not my strong suit so if this could have been done more elegantly, please edit my script.
Public Overrides Sub Input0_ProcessInputRow(ByVal Row As Input0Buffer)
' Ensure we have data to work with
If Not Row.ColumnName_IsNull Then
' Test whether it's a number or not
' TryCast doesn't work with value types so I'm going the lazy route
Try
' Cast to an integer and then back to string because
' my vb is weak
Row.ColumnName = CStr(CType(Row.ColumnName, Integer))
Catch ex As Exception
Row.ColumnName = 0
End Try
End If
End Sub