 Posts: 113
 Karma: 3
 Thank you received: 5
Expression Manager: Nested Equations?
4 years 2 months ago #90492
by Fred01
Can you use the result of equation question A in equation question B on the same page and have it computed and displayed correctly?
I am trying this and the first equation looks ok, but the second one doesn't seem to pick up the result of the first.
For example, assume a groupbygroup survey, with the following group:
Q1 (numeric) Apples? Response: 6
Q2 (numeric) Bananas? Response: 3
Q3 (equation) Subtotal fruit. Expression {Q1+Q2}. Displays 9.
Q4 (numeric) Carrots? Response: 2
Q5 (equation) Fruit minus Veggies. Expression {Q3  Q4}. Should display 7, but is showing 2.
I am using 1.92+ (the final build)
I am trying this and the first equation looks ok, but the second one doesn't seem to pick up the result of the first.
For example, assume a groupbygroup survey, with the following group:
Q1 (numeric) Apples? Response: 6
Q2 (numeric) Bananas? Response: 3
Q3 (equation) Subtotal fruit. Expression {Q1+Q2}. Displays 9.
Q4 (numeric) Carrots? Response: 2
Q5 (equation) Fruit minus Veggies. Expression {Q3  Q4}. Should display 7, but is showing 2.
I am using 1.92+ (the final build)
Please Log in to join the conversation.
4 years 2 months ago #90496
by TMSWhite
If you depend upon LimeSurvey or the support team, please give generously to our 2012 fundraiser .
It should work. Please upload a sample survey or group demonstrating the problem.
If you depend upon LimeSurvey or the support team, please give generously to our 2012 fundraiser .
 Expression Manager (EM):
Documentation

Sample Surveys

How Tos

Show Logic File

Upgrading to 1.92+  Excel Style for Survey Structure Import/Export
Please Log in to join the conversation.
4 years 2 months ago #90503
by Fred01
Hi Tom,
I probably should have titled the topic "Cascading Equations." The actual survey is REALLY long, but here's a short one demonstrating the problem.
The equations work correctly with small numbers. but starts to fail when the numbers get bigger (q3 >=1000)
Looking at this some more, it seems like has to do with using number_format() on the equations, which I didn't mention originally. The original survey (the long one) is mostly financial/money questions and I wanted to display the equations rounded and with commaseparators.
So when q3 gets to 1000, then the number_format inserts the comma and the 2nd equation is looking at the first one and saying "That's not a number"?
Do you think that is the problem? If so, is there some way to recast the string as a number? I tried changing q5 to {number_format(intval(q3)  q4)}, but that didn't help.
I probably should have titled the topic "Cascading Equations." The actual survey is REALLY long, but here's a short one demonstrating the problem.
The equations work correctly with small numbers. but starts to fail when the numbers get bigger (q3 >=1000)
Looking at this some more, it seems like has to do with using number_format() on the equations, which I didn't mention originally. The original survey (the long one) is mostly financial/money questions and I wanted to display the equations rounded and with commaseparators.
So when q3 gets to 1000, then the number_format inserts the comma and the 2nd equation is looking at the first one and saying "That's not a number"?
Do you think that is the problem? If so, is there some way to recast the string as a number? I tried changing q5 to {number_format(intval(q3)  q4)}, but that didn't help.
Please Log in to join the conversation.
4 years 2 months ago #90506
by Fred01
The other problem with the number_format() is that is will save to the DB as a string. For example, 100000 is saved as 100,000. Just as it is displayed. It will create some problems down the line when we export the data for analysis.
What I need to do is display numbers with commaseparators and rounding, but have the value stay a number and be saved that way.
What I need to do is display numbers with commaseparators and rounding, but have the value stay a number and be saved that way.
Please Log in to join the conversation.
4 years 2 months ago #90507
by TMSWhite
If you depend upon LimeSurvey or the support team, please give generously to our 2012 fundraiser .
I recommend storing numbers instead of formatted strings via your equations. You can use number formatting options to have those valuea dispay with formating. I will take a look at the actual survey tomorrow.
If you depend upon LimeSurvey or the support team, please give generously to our 2012 fundraiser .
 Expression Manager (EM):
Documentation

Sample Surveys

How Tos

Show Logic File

Upgrading to 1.92+  Excel Style for Survey Structure Import/Export
Please Log in to join the conversation.
4 years 2 months ago #90509
by Fred01
Awesome, thanks Tom.
We use javascript masking on the numeric inputs to get the #,### format. When people are entering numbers in the millions, it's easy to make mistakes without them. Unfortunately you can't use masking on Equations as far as I can tell.
I also considered as an alternative trying to replace the Equation with a Numeric question and put the expression in the Default value. However, the Default expression doesn't update in real time when the inputs are on the same page; you have to put it on a following page, and we need it on the same page.
We use javascript masking on the numeric inputs to get the #,### format. When people are entering numbers in the millions, it's easy to make mistakes without them. Unfortunately you can't use masking on Equations as far as I can tell.
I also considered as an alternative trying to replace the Equation with a Numeric question and put the expression in the Default value. However, the Default expression doesn't update in real time when the inputs are on the same page; you have to put it on a following page, and we need it on the same page.
Please Log in to join the conversation.
4 years 2 months ago #90514
by TMSWhite
If you depend upon LimeSurvey or the support team, please give generously to our 2012 fundraiser .
Fred
Try this version of your survey.
I always use equations as hidden calculations, then display the resulting values in a different question. That way you can store pure numbers that are easy to manipulate and analyze, but you can display them however you want.
As you can see from this demo, cascaded Equations work just fine on the same page.
Here is a screen shot.
Tom
Try this version of your survey.
I always use equations as hidden calculations, then display the resulting values in a different question. That way you can store pure numbers that are easy to manipulate and analyze, but you can display them however you want.
As you can see from this demo, cascaded Equations work just fine on the same page.
Here is a screen shot.
Tom
If you depend upon LimeSurvey or the support team, please give generously to our 2012 fundraiser .
 Expression Manager (EM):
Documentation

Sample Surveys

How Tos

Show Logic File

Upgrading to 1.92+  Excel Style for Survey Structure Import/Export
Please Log in to join the conversation.
4 years 2 months ago #90516
by Fred01
Now why didn't I think of that? . Will try it out today.
This survey actually has over 500 of these equations, and now we are doubling the number of questions. Although the display questions don't create a column in the survey_NNN table at least. It's a good thing I am using Excel and your awesome Excel importer to create all the questions.
Maybe in a future version all this masking and formatting will be baked in and a lot easier to use.
This survey actually has over 500 of these equations, and now we are doubling the number of questions. Although the display questions don't create a column in the survey_NNN table at least. It's a good thing I am using Excel and your awesome Excel importer to create all the questions.
Maybe in a future version all this masking and formatting will be baked in and a lot easier to use.
Please Log in to join the conversation.