I would like to have a field in a report show the ratio of two numbers i.e.
New Customers is 20 and Lost Customers is 24, and have the ratio field to show 5:6 ratio. I know how to do it in an Excel Spreadsheet (=B1/GCD(B1,B2)&":"&B2/GCD(B1,B2), B1 is new customer and B2 is Lost Customer, but I have not been able to figure out how to make it work in an Access report. I tried to do it in a query, I've tried this code I found on the forum, but could not make is work for my problem.
Appreciate any help I can get on this matter.
Thanks, MacGirlNC
Public Function CalcGCD(OneNumber As Long, OtherNumber As Long) As Long
Dim lngSmallest As Long
Dim lngGCD As Long
Dim i As Long
lngSmallest = IIf(OneNumber < OtherNumber, OneNumber, OtherNumber)
For i = lngSmallest To 1 Step -1
If (OneNumber Mod i = 0) And (OtherNumber Mod i) = 0 Then
CalcGCD = i
Exit Function
End If
Next i
CalcGCD = 1
End Function
New Customers is 20 and Lost Customers is 24, and have the ratio field to show 5:6 ratio. I know how to do it in an Excel Spreadsheet (=B1/GCD(B1,B2)&":"&B2/GCD(B1,B2), B1 is new customer and B2 is Lost Customer, but I have not been able to figure out how to make it work in an Access report. I tried to do it in a query, I've tried this code I found on the forum, but could not make is work for my problem.
Appreciate any help I can get on this matter.
Thanks, MacGirlNC
Public Function CalcGCD(OneNumber As Long, OtherNumber As Long) As Long
Dim lngSmallest As Long
Dim lngGCD As Long
Dim i As Long
lngSmallest = IIf(OneNumber < OtherNumber, OneNumber, OtherNumber)
For i = lngSmallest To 1 Step -1
If (OneNumber Mod i = 0) And (OtherNumber Mod i) = 0 Then
CalcGCD = i
Exit Function
End If
Next i
CalcGCD = 1
End Function
Need Ratio of Two Numbers in a field in a report.
0 commentaires:
Enregistrer un commentaire