Dividing values in two datasets

Copper Contributor

Hello,

 

In short, I am trying to divide two values, one in DatasetC and one in DatasetA. I have tried to use Lookup to do it, but to no avail.

 

I am recreating a report and plugging it into SSRS. I have rewritten the report in SQL and it contains 6 parts, A, B, C, D, E, F and G. I am needing to divide DatasetC by DatasetA in order to get a percentage. I have looked into this and all I can find is to use Lookup, but when I do is produces an error. Below is the formula I am using. They all connect to the same datasource. Any advice would be appreciated.

 

=Lookup
(
Fields!Outstanding.Value,
Fields!Outstanding.Value,
Fields!Balance.Value,
"PartD"
)
/
Lookup
(
Fields!Outstanding.Value,
Fields!Outstanding.Value,
Fields!Balance.Value,
"PartA"
)

 

Thank you

1 Reply
Normally, you bound a tablix to a specific dataset. Let say you bound the tablix to datasetC. In a textbox, you do =Fields!column1.Value. Let say that texbox name is called Textbox1. Then, in the next textbox, you want to get value from datasetA. You would put something like this in the expression: =First(Fields!column2.Value,"datasetA"). Lets name that textbox Textbox2.
Then in the next textbox where you want to divide, use expression of =ReportItems!Textbox1.Value / ReportItems!Textbox2.Value. If you know about a code, there is a code.Divide that you can use, to handle 0 division, because you can get error when trying to divide value 0 or null. Then, if you have this Divide function, you would use this in the expression:
=code.Divide(ReportItems!Textbox1.Value,ReportItems!Textbox2.Value)

In Report Properties, there is a table called Code. Click on that and paste this:

Public Function Divide(Num1 as double, Num2 as double) AS double
IF IsNothing(Num1) Or IsNothing(Num2) Or Num1 = 0 Or Num2 = 0 Then
Divide = 0
ELSE
Divide = Num1 / Num2
END IF
End Function

Good luck!