Formula for calculating the value of a field

We want to create a formula to calculate the value of a field under the following conditions:

"If the value of the field with ID=23 is = to 2 months, then increase the value of the field with ID 24 by 10% and divide by 2, if the value of the field with ID=23 is = to 3 months, then increase the value of the field with ID 24 by 10% and divide by 3, and so… "

We have entered the following formula in a field and it does not work for us, could you tell us how should be the structure of the formula?

if( rgar( $form_data, ‘23’ ) == ‘2 meses’,
( rgar( $form_data, ‘24’ ) * 1.1 ) / 2,
if( rgar( $form_data, ‘23’ ) == ‘3 meses’,
( rgar( $form_data, ‘24’ ) * 1.1 ) / 3,
if( rgar( $form_data, ‘23’ ) == ‘4 meses’,
( rgar( $form_data, ‘24’ ) * 1.15 ) / 4,
rgar( $form_data, ‘24’ )
)
)

Thank you in advance!

This isn’t supported out of the box. The team at Gravity Wiz have an add-on for advanced calculations:

1 Like

As Richard mentioned, Advanced Calculations is a good fit here. The calculation would look something like this:

if( F23 == 2 ):
	( F24 * 1.1 ) / 2
elseif( F23 == 3 ):
	( F24 * 1.1 ) / 3
elseif( F23 == 4 ):
	( F24 * 1.15 ) / 4
else:
	F24
endif;

Do note that Advanced Calculations cannot do if/elseif statements on strings, only numeric values. Assuming your 2/3/4 month values are in a choice-based field, you’ll need to set the values of those fields to be integers, like this:

Thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.