How do I perform complex calculations using variables | Community
Skip to main content
Answered

How do I perform complex calculations using variables


Hello,

I have variables named A, B, C, D,

How do I perform

((variable A-Variable B)*0.9)*((1+0.025)/(Variable c-variable d))*25

This is to find out retirement savings amount needed based on current age, retirement age, current savings, expected annual saving after retirement etc.

Best answer by john.desborough

@Vinayak - you can create this stepwise in Typeform’s logic rules and some ‘sub-total’ variables but is has some restrictions due to the number of decimal places that Typeform will show ( @Liz - i think it is still limited to 2 decimals, correct?)

create something like these variables

  • sub_a numeric default = 0
  • sub_c numeric default = 0
  • sub_calc_1 numeric default = 1025
  • v_total

logic rules something like this (your variables referred to by simple letters): 

  • If A greater than 0 add A to sub_a
  • if C greater than 0 add C to sub_c

 

  • ((variable A-Variable B)*0.9)
  • if B greater than or equal 0 then subtract B from sub_a
  • if A greater than 0 multiply sub_a by 9
  • if A greater than 0 divide sub_a by 10   (this one and the one above are necessary since you can’t input a decimal number, only whole numbers - but this gives you the *.9 result)
  • if A greater than 0 add sub_a to v_total
  •  
  • note: typeform only handles 2 decimal places so your 0.025 so you might have to consider either starting with 1025 and eventually divide by 1000 or just deal the fact that you are not going to get to the 3 decimal accuracy inside typeform
  • ((1+0.025)/(Variable c-variable d))
    • same as 1025/ ((Variable c-variable d)*1000)
    • if C greater than 0 add C to sub_c
    • if D greater than or equal 0 then subtract C from sub_c
    • if C greater than 0 then multiply sub_c by 1000
    • (since we set sub_calc_1 to 1025)
      • if C greater than 0 then divide sub_calc_1 by sub_c
  • if C greater than 0 then multiply v_total by sub_calc_1
  • if A greater than 0 then multiply v_total by 25

that should do the trick .. BUT remember that your output will only be to 2 decimals in Typeform 

 

if you push this all to a google sheet you could do the calculation as a formula there.. 

hope this makes sense.. 

des

View original

4 replies

Liz
Community Team
Forum|alt.badge.img+5
  • Tech Community Advocate
  • 14857 replies
  • July 5, 2023

Hi @Vinayak Happy Wednesday! I hope you’re having a great week so far. 

We don’t have the ability to do complex calculations like this within the form builder, though @john.desborough has created some nifty solutions completing these calculations outside of Typeform, such as in a Google spreadsheet. 


john.desborough
Forum|alt.badge.img+6
  • Certified Partner & Champion
  • 5260 replies
  • Answer
  • July 5, 2023

@Vinayak - you can create this stepwise in Typeform’s logic rules and some ‘sub-total’ variables but is has some restrictions due to the number of decimal places that Typeform will show ( @Liz - i think it is still limited to 2 decimals, correct?)

create something like these variables

  • sub_a numeric default = 0
  • sub_c numeric default = 0
  • sub_calc_1 numeric default = 1025
  • v_total

logic rules something like this (your variables referred to by simple letters): 

  • If A greater than 0 add A to sub_a
  • if C greater than 0 add C to sub_c

 

  • ((variable A-Variable B)*0.9)
  • if B greater than or equal 0 then subtract B from sub_a
  • if A greater than 0 multiply sub_a by 9
  • if A greater than 0 divide sub_a by 10   (this one and the one above are necessary since you can’t input a decimal number, only whole numbers - but this gives you the *.9 result)
  • if A greater than 0 add sub_a to v_total
  •  
  • note: typeform only handles 2 decimal places so your 0.025 so you might have to consider either starting with 1025 and eventually divide by 1000 or just deal the fact that you are not going to get to the 3 decimal accuracy inside typeform
  • ((1+0.025)/(Variable c-variable d))
    • same as 1025/ ((Variable c-variable d)*1000)
    • if C greater than 0 add C to sub_c
    • if D greater than or equal 0 then subtract C from sub_c
    • if C greater than 0 then multiply sub_c by 1000
    • (since we set sub_calc_1 to 1025)
      • if C greater than 0 then divide sub_calc_1 by sub_c
  • if C greater than 0 then multiply v_total by sub_calc_1
  • if A greater than 0 then multiply v_total by 25

that should do the trick .. BUT remember that your output will only be to 2 decimals in Typeform 

 

if you push this all to a google sheet you could do the calculation as a formula there.. 

hope this makes sense.. 

des


Liz
Community Team
Forum|alt.badge.img+5
  • Tech Community Advocate
  • 14857 replies
  • July 7, 2023

john.desborough
Forum|alt.badge.img+6
  • Certified Partner & Champion
  • 5260 replies
  • July 7, 2023

@Liz - #mathbrainatwork