Show Value in row before the Previous Row in SSRS - reporting-services

I am building a report in SSRS and wondering how to show the value in the column 2 rows before. I have used the Previous expression to retrieve the one before, but now I need the one before that.
Any help would be much appreciated
Thank you
Sam
Shared Dataset looks like this:
https://i.stack.imgur.com/Ii5y6.jpg

You can use custom code to set and get the value.
Public Dim Previous2 As String
Public Dim Previous As String
Public Function SetPrevious2 ( s As String) As String
Previous2 = Previous
Previous = s
Return Previous2
End Function
For the cell use and expression like the one below
= Code.SetPrevious2(Previous(Fields!MyValue.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")
)

Passing a Field for Access Query to a Module Function as an Array

I am trying to write a function in a module that we take a field from a MS ACCESS query that is passed to it and return the values of the field to another field in the Query.
The code that I have written in the module is provided below.
Public Function YearAmps(ByRef array1() As Double)
Dim array2(0 To UBound(array1())) As Double
Dim I
For I = 0 To UBound(array2())
array2(I) = array1(I)
Next I
YearAmps = array2
End Function
When I put the following in the Query field: YearAmps([SN]), where YearAmps is the function that I am calling and SN is the field that I am passing to the function and run the code, I get an error.
Does anyone know where I am going wrong. Is is possible to pass a field from an Query as an array in a Module and then return that array?
Any help would be greatly appreciated.

Sum of Averages in SSRS

I have a table created a report where there should be a field with sum of Avg.
Please find the below image
I am getting the average but i need to sum the average to display A.
Have you tried adding a custom function to the report, as outlined here?
This person wrote this custom function:
Dim Test as double
Public Function Testing(Byval value as Double, ByVal reset as Boolean) as Double
Test = Test + value
Testing = Test
If reset = TRUE Then
Test = 0
End If
End Function
At the footer of the group call Code.Testing([value], False) then call it again outside of the group with code.Testing([value],True) to reset. Worked for me :)

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

Populating multiple values in rdlc reporting

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.