Dynamic Calc - return lesser value

jordielane
New Contributor III

I'm trying to do a dynamic calc to determine lesser value of an account or 500,000. I have very little experience with vb.net so this was as far as I got but it doesn't work.

If api.Data.GetDataCell("A#RPT_Cash") > "500000" Then
  Return "500000"
Else If api.Data.GetDataCell("A#RPT_Cash") < "500000" Then
  Return api.Data.GetDataCell("A#RPT_Cash")
End If 
1 ACCEPTED SOLUTION

MikeG
Contributor III

Try this - then check your ErrorLog and confirm you are getting an Amount, you may need to provide additional POV to get the correct value for A#RPT_Cash.

Dim value As Decimal = api.Data.GetDataCell("A#RPT_Cash").CellAmount
Dim threshold As Decimal = 500000
Brapi.ErrorLog.LogMessage(si, "in Dynamic Calc, Entity= " & api.Pov.Entity.Name & ", value= " & value & ", threshold= " & threshold)
If value > threshold Then
Return threshold
Else
Return value
End If

View solution in original post

6 REPLIES 6

MikeG
Contributor III

Try this:

Dim value as decimal = api.Data.GetDataCell("A#RPT_Cash").CellAmount

BRapi.ErrorLog.LogMessage(si, "in Dynamic calc - Entity= " & api.pov.entity.Name & ", value= " & value)

If value < 500000 Then

You may need to provide additional POV.  You need the .CellAmount after the api.Data.GetDataCell and when comparing a value no quotes are required.  Quotes are needed for a String comparison.

Hope this helps.

jordielane
New Contributor III

Thank you for the tips. I'm not sure if its relevant but this calculation is being stored as an account member.  I need it to return the lesser of the A#Rpt_Cash value or 500,000. What should the return values be after the if statement? I tried modifying what I had originally based on your reply but it still didn't work. 

MikeG
Contributor III

Try this - then check your ErrorLog and confirm you are getting an Amount, you may need to provide additional POV to get the correct value for A#RPT_Cash.

Dim value As Decimal = api.Data.GetDataCell("A#RPT_Cash").CellAmount
Dim threshold As Decimal = 500000
Brapi.ErrorLog.LogMessage(si, "in Dynamic Calc, Entity= " & api.Pov.Entity.Name & ", value= " & value & ", threshold= " & threshold)
If value > threshold Then
Return threshold
Else
Return value
End If

jordielane
New Contributor III

This worked, thank you!

Please comment out or delete the LogMessage write, you don't want that running after you've completed your testing.  Glad that work for you @jordielane !

RobbSalzmann
Valued Contributor

For maintenance and readability, consider this could be a one or two line solution using the System Math API:

Dim compareVal as Decimal = api.Data.GetDataCell("A#RPT_Cash").CellAmount
Return System.Math.Min(compareVal, 500000)