Skip to main content
Newcomer
Jun 21, 2023 4:32 PM UTC
Solved

Dynamic Calc - return lesser value

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 
MikeG
MikeGAnswer
Contributor
Jun 21, 2023 5:25 PM UTC

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

6 replies

MikeG
Contributor
Jun 21, 2023 4:40 PM UTC

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.

Newcomer
Jun 21, 2023 5:19 PM UTC

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
MikeGAnswer
Contributor
Jun 21, 2023 5:25 PM UTC

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

Newcomer
Jun 22, 2023 4:26 PM UTC

This worked, thank you!

MikeG
Contributor
Jun 22, 2023 5:02 PM UTC

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
Employee - Advisor
Employee - Advisor
Jun 26, 2023 2:36 PM UTC

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)