问题
I have an SSRS tablix that pulls data from several datasets resembling the following (changed to avoid explaining the exact context) :
There is an employees dataset that gives the employee ID, the employee ID of their manager and the number of tasks they have completed e.g.
Manager Employee Tasks
DATA003 DATA001 118
DATA003 DATA002 42
DATA003 DATA003 94
DATA003 DATA004 118
From another database there is a dataset that gives the number of complaints against each employee, and the number that were upheld.
The tablix, linked to the employees table that gives the employee number, name, the sum of tasks, then does lookups to find the complaints, upheld complaints and calculate the % of tasks that resulted in complaints or upheld complaints.
e.g.
=lookup(Fields!EMPLOYEE_CODE.Value,Fields!EMPLOYEE_CODE.Value,Fields!Number_of_Complaints.Value,"ComplaintsPerEmployee")
This is then grouped on the managers field.
The figures for individual employees is okay, the problem arises when I try to sum those that are looked up. What I expected to be able to do when I started out was an expression like
=sum(multilookup(
Fields!EMPLOYEE_CODE.Value,
Fields!EMPLOYEE_CODE.Value,
Fields!Number_of_Complaints.Value,
"ComplaintsPerEmployee"))
in the row of the tablix that gives the totals for each manager. However, this gives an error. When I try:
=join(Fields!EMPLOYEE_CODE.Value,",")
I get an error. So I'm confused - why does this not give me the array of employee codes to pass to the join or the multilookup the same way I can just do Sum(TASKS) to sum the tasks for the employees under each manager.
I can't easily join the tables in SQL at the source as they are in different databases, and I would really rather not duplicate any of the data in other databases. I know the problem is not with the sum because the join given above doesn't work, and I've already tried the following custom code in place of sum:
Function SumLookup(ByVal items As Object()) As Decimal
If items Is Nothing Then
Return Nothing
End If
Dim suma As Decimal = New Decimal()
Dim ct as Integer = New Integer()
suma = 0
ct = 0
For Each item As Object In items
suma += Convert.ToDecimal(item)
ct += 1
Next
If (ct = 0) Then return 0 else return suma
End Function
This does not work as the multilookup is not working to pass values to it. I've tried reading up on tablixes, the expressions and so on and I seem to be swamped by stuff that I either already know or which isn't relevant - can anyone point me in the right direction?
回答1:
=SUM(lookup(Fields!EMPLOYEE_CODE.Value,Fields!EMPLOYEE_CODE.Value,Fields!Number_of_Complaints.Value,"ComplaintsPerEmployee"))
来源:https://stackoverflow.com/questions/28676808/summing-lookups-in-ssrs