Answered

How to add multiple step equations into your survey w/ Variables


Help!

I’m trying to do multiple calculations summing up a total value while also calculating a “graded” score based off number values and then multiple choice questions. 

Is it possible to Add a Two step equation into one calculation while also using the same variable in a different question without affecting the value of the original value?

 

This is the simple one:

the calculation would be something like this. Based off of answers to Q4 which is value based (number). 

Ex Answer= 3 

ADD to Leads

 

Then if answers to Q7 is A,B, or C, than

Multiply Leads by 2

 

Difficult Part:

Answer Q2:

If answer in Q8 are B or C than multiply (Answer Q2) by 50%(Leads)

 

is this possible? How Do I set up variables to create multi step calculations like this?!

 

 

 

icon

Best answer by john.desborough 5 May 2022, 05:14

View original

11 replies

Userlevel 7
Badge +5

Reaching out to the calculations master @john.desborough to see if he happens to know how to do this! 😁

@john.desborough Is this something you could help me out with?

Userlevel 7
Badge +6

@kevin_0912345 - sorry, i’ve been tied up with client meetings all day.. i will try to get a response to this one for you later tonight (eastern time) when the rest of the house is asleep.

 

 

Userlevel 7
Badge +6

@kevin_0912345 - here’s a little sample file that tries to mirror what you described

note: in your description of difficult part, you mention Q2, i assumed that it was a separate question (the second) in your typeform and NOT the ‘second’ question you referenced ie q7. 

and here are the screen caps of the logic rules and variables - note that in my q1, i took the answer and created the 50% of answer variable right away: the math you describe is = a * .5 * b type structure, so it doesn’t matter if you multiply leads or the answer from q2 by 50% as it all works out the same. 

 

 

 

hope you can make sense of this.. 

 

des

Userlevel 7
Badge +5

Hi @kevin_0912345 Were you able to give these suggestions a go? Let us know!

Badge

Wow this is a lot of work… the scenario I need to do is much more complex and collects several numbers to then perform a calculation. Can Typeform please add a formula variable that can accept calculations / formulas from other variables? That would be an easy solution here (I think).

In a simplified format… if I have x number of workers (@workers variable) that get paid an hourly rate (@hourlyrate variable) I could create a variable formula that was called @pay which the default value could be @workers * @hourlyrate.

Am I simplifying it too much?

Thanks!

Userlevel 7
Badge +5

Hi @AD4 That’s a great question! We don’t have the capability to perform these kinds of calculations in the form, but I believe @john.desborough has created workarounds for this outside of typeform using Google Sheets. 

Userlevel 7
Badge +6

@Liz  @AD4  - i think what is really being asked - and i would absolutely love for this to be possible - is to have the ability in the ‘create variables’ feature to do something like this:

create variable v_pay numeric default = q1 * q2

where q1 is the answer to the number of workers question and q2 the hourly rate 

this way you would not have to use a logic rule(s) to add q1 to @v_pay and then multiply @v_pay by q2

 

but in terms of ‘can you do complex calculations with typeform logic’ - yes you can but you have to do them step-wise…there are some limits on what you can do but i have been able to take a BMI/TDEE formula to calculate target caloric intake and then break that down into distribution of carbs, fats and proteins (based on input from the client ie they had the formula) … 

just a thought

 

des

Badge

Yes this would be great… so you could essentially collect numeric values from multiple pages and just have one variable with the formula in it. Thanks!

John, could you share what the logic / calculation screens look like for the calculation you mentioned above? I get if you can’t share publicly… perhaps a DM?

Thanks!

Userlevel 7
Badge +6

@AD4 - i agree that would be wonderful IF that was in the variables section.. but because it isn’t it’s just a step-wise bit you have to do .. 

 

unfortunately, since a client paid me for that work, it’s ‘their’s’ and they would have to agree with me in terms of sharing it.. but let’s just say that there were 26 variables and 3 subtotals that were involved in the calculations .. all done with simple logic rules in Typeform. 

BUT i wrote it all out step wise on paper before i started coding it so that all i had to do was input the simple logic to get me through ..

sort of taking something like the stuff below and making it work one step at a time

 

((a+b)*(c+d)/f)*(b+d)*(g+(a+c)*h)) / 4 ..

 

v_1 = a+b

v_2 = c+d

….

Badge

Thanks so much for this John!

Reply