Sum of Averages in SSRS - reporting-services

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

Related

Show Value in row before the Previous Row in SSRS

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

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

Filtering Information in A Report Using VBA-Access - Finding the next avaliable null field

I'm trying to organize information in a report in a certain way
I have 9 fields that will be used to store the label for the information
and another 9 fields that store the actual value of the information.
Whenever a field is full, I want it to place the information in the next available field. So that there will be no blank fields in between information.
The issue is that when trying to run this code which triggers two functions, it is not updating the report I referenced to in the two functions, nor is it pulling information from SpecSheetQuery, and I can't figure out why. My guess is that I'm not referencing the information correctly. I also have to figure out how to run this code individually on each record.
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Servings = DLookup("[servings]", "SpecSheetQuery")
Calories = DLookup("[calories]", "SpecSheetQuery")
If Not IsEmpty(Servings) Then
OpenSlot ("Servings")
OpenFact (Servings)
End If
If Not IsEmpty(Calories) Then
OpenSlot ("Calories")
OpenFact (Calories)
End If
End Sub
OpenSlot function, puts title/label of information into field1 ( which is a field on the report) on the first null/empty field. so that no space is left blank.
Option Compare Database
Option Explicit
Public Function OpenSlot(Slot As String)
Debug.Print Reports!SpecSheet!field1.Value
If Reports!SpecSheet!field1.Value = Null Then
Debug.Print "Slot1"
Slot = Reports!SpecSheet!field1.Value
Debug.Print Reports!SpecSheet!field1.Value
ElseIf Reports!SpecSheet!field2.Value = Null Then
Reports!SpecSheet!field2.Value = Slot
End If
End Function
OpenFact function, puts fact into nut1 ( which is a field on the report) on the first null/empty field. so that no space is left blank.
Public Function OpenFact(fact As String)
If Reports!SpecSheet!nut1.Value = Null Then
Reports!SpecSheet!nut1.Value = fact
Debug.Print Reports!SpecSheet!nut1.Value
ElseIf Reports!SpecSheet!nut2.Value = Null Then
Reports!SpecSheet!nut2.Value = fact
End If
End Function
I'm trying to store this information into this report.
Any help would be greatly appreciated.

SSRS 2008r2 Using Aggregate on field with an Expression

SSRS 2008r2
I'm trying to perform an aggregate (Sum) on a field within a GROUPing that contains an expression.
The field where I want to SUM to appear is within a different GROUPing.
I've created the following Function within Report Properties
Dim public tot_OT_Hrs As Decimal
Public Function Add_OT_Hrs(ByVal OT_Hrs As Decimal) AS Decimal
tot_OT_Hrs = tot_OT_Hrs + OT_Hrs
return OT_Hrs
End Function
Public Function GetTotal()
return tot_OT_Hrs
End Function
I've added a call to the "Add_OT_Hrs" function in the field where the expression is and this works fine.
=Code.Add_OT_Hrs(
IIF(Sum(Fields!HrsWorked.Value) > Parameters!StdWorkingHrs.Value,
Sum(Fields!HrsWorked.Value) - Parameters!StdWorkingHrs.Value + Sum(Fields!Rate1Hrs.Value)
, Sum(Fields!Rate1Hrs.Value )
)
)
Fields!Rate1Hrs.Value is the field in which the expression resides in and Fields!HrsWorked.Value is an adjacent field
However, the field where I want to total to appear I've added the following
=Code.GetTotal()
All that is returned here is 0 (zero) on every row in the GROUPing. If I initialise the Dim public tot_OT_Hrs As Decimal variable to say 1.2 then 1.2 is returned on every row in the GROUPing. The Add_OT_Hrs function isn't working as expected.
Where am I going wrong?
Thanks in advance.
Looks to me that you are converting in the wrong order and also to the wrong data type. In the code example that you used you were converting the sum to a double which is not the correct data type. There is a notable difference between a double and decimal when using custom functions.
I tested this with a very small dataset as follows
select '1.2'
union all
select '1.8'
Then applied the following custom code
Dim public total as decimal
Public Function AddTotalr(ByVal r AS decimal) AS decimal
total = total + r
return r
End Function
Public Function GetTotalr()
return total
End Function
The order of your explicit conversion is vital. You have to convert the value before you sum the total so that you are working with consistent data types.
=code.addtotalr(sum(cdec(Fields!ID.Value)))
Even with the correct data type the this will produce an error because you are attempting to sum what is, most likely, being interpreted as a character string.
=code.addtotalr(cdec(sum(Fields!ID.Value)))
-----------edit ------------------------
As a test to see what the return on the function is change your function to
Dim public total as decimal
Public Function AddTotalr(ByVal r AS decimal) AS decimal
total = total + r
return total
This should give you a running total of the items processed and the last value in the list should match what your total should be.
I decided to do this in the proc.
It works out quite well now.

SSRS Calculated field Skip NULL

I am trying to make some calculations in a SSRS report.
I have times in the column Hours: "08:25:21" and some of them are NULL.
WORKS:
=IIF(IsNothing(Fields!Hours.Value), Nothing,Fields!Hours.Value)
I want to extract the hours from the time:
ERROR for blank:
=IIf(IsError(Hour(Fields!Hours.Value.toString())),Nothing,Hour(Fields!Hours.Value.toString()))
=IIf(IsNothing(Fields!Hours.Value),Nothing,Hour(Fields!Hours.Value.toString()))
How can I do this so I will get a Nothing when no Hours.value is present?
Danny
If your Hours field is a TimeSpan, you can use the TimeSpan.Hours property.
I've been able to make this work by adding a function to the code of the report.
Function GetHours(timeSpan as TimeSpan) As String
If timeSpan = TimeSpan.Zero
Return Nothing
Else
Return timeSpan.Hours
End If
End Function
Now you can use this expression: =Code.GetHours(Fields!Hours.Value).