Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:
  • Page:
  • 1
  • 2

TOPIC: Expression Manager: Nested Equations?

Expression Manager: Nested Equations? 3 years 8 months ago #90492

  • Fred
  • Fred's Avatar
  • Offline
  • Expert Lime
  • Posts: 147
  • Thank you received: 5
  • Karma: 3
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 group-by-group 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)
The administrator has disabled public write access.

Expression Manager: Nested Equations? 3 years 8 months ago #90496

  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 758
  • Thank you received: 83
  • Karma: 37
It should work. Please upload a sample survey or group demonstrating the problem.
The administrator has disabled public write access.

Expression Manager: Nested Equations? 3 years 8 months ago #90503

  • Fred
  • Fred's Avatar
  • Offline
  • Expert Lime
  • Posts: 147
  • Thank you received: 5
  • Karma: 3
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 comma-separators.

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 re-cast the string as a number? I tried changing q5 to {number_format(intval(q3) - q4)}, but that didn't help.
The administrator has disabled public write access.

Expression Manager: Nested Equations? 3 years 8 months ago #90505

  • Fred
  • Fred's Avatar
  • Offline
  • Expert Lime
  • Posts: 147
  • Thank you received: 5
  • Karma: 3
Here's the survey...
Attachments:
The administrator has disabled public write access.

Expression Manager: Nested Equations? 3 years 8 months ago #90506

  • Fred
  • Fred's Avatar
  • Offline
  • Expert Lime
  • Posts: 147
  • Thank you received: 5
  • Karma: 3
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 comma-separators and rounding, but have the value stay a number and be saved that way.
The administrator has disabled public write access.

Expression Manager: Nested Equations? 3 years 8 months ago #90507

  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 758
  • Thank you received: 83
  • Karma: 37
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.
The administrator has disabled public write access.

Expression Manager: Nested Equations? 3 years 8 months ago #90509

  • Fred
  • Fred's Avatar
  • Offline
  • Expert Lime
  • Posts: 147
  • Thank you received: 5
  • Karma: 3
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.
The administrator has disabled public write access.

Expression Manager: Nested Equations? 3 years 8 months ago #90514

  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 758
  • Thank you received: 83
  • Karma: 37
Fred-

Try this version of your survey.


File Attachment:

File Name: limesurvey...3381.lss
File Size:31 KB



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
The administrator has disabled public write access.

Expression Manager: Nested Equations? 3 years 8 months ago #90516

  • Fred
  • Fred's Avatar
  • Offline
  • Expert Lime
  • Posts: 147
  • Thank you received: 5
  • Karma: 3
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.
The administrator has disabled public write access.

Expression Manager: Nested Equations? 3 years 8 months ago #90519

  • Fred
  • Fred's Avatar
  • Offline
  • Expert Lime
  • Posts: 147
  • Thank you received: 5
  • Karma: 3
Works great. Thanks Tom.
The administrator has disabled public write access.

Expression Manager: Nested Equations? 3 years 8 months ago #90521

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5984
  • Thank you received: 368
  • Karma: 260
Fred wrote:
Maybe in a future version all this masking and formatting will be baked in and a lot easier to use.
At Limesurvey 2.1 there will also be a thousand separator available. So when you set the decimal separator to "." (US number format), the thousands separator will automatically be set to "," and vice versa.

This is implemented for the numeric question types to make large numbers easier to read when inputting them.
I'm not sure if this might cause any conflicts e. g. when using EM because only the number display is adjusted while the actual storing of the value should not have changed, but if someone notices any problems, please file a bug report and post the link to the report here.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Expression Manager: Nested Equations? 3 years 8 months ago #90523

  • Fred
  • Fred's Avatar
  • Offline
  • Expert Lime
  • Posts: 147
  • Thank you received: 5
  • Karma: 3
Mazi wrote
At Limesurvey 2.1 there will also be a thousand separator available. So when you set the decimal separator to "." (US number format), the thousands separator will automatically be set to "," and vice versa.

Yes, Denis told me a little about that. Hopefully it will work on Inputs so we don't have to do all this custom JS masking. And it can work equivalently in Expressions just for display but without saving to the database. It would be nice if we could get prefix/suffix into Equations somehow as well. I use them for $ and % signs.

This business of having to create two questions for everything is not very user-friendly for typical survey creator

What is the roadmap for 2.1 anyway? I keep hearing about it, but there's not much on the site. Maybe this could use an update :)
docs.limesurvey.org/LimeSurvey+roadmap&highlight=2.1
The administrator has disabled public write access.

Aw: Re: Expression Manager: Nested Equations? 3 years 8 months ago #90524

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5984
  • Thank you received: 368
  • Karma: 260
Fred wrote:
This business of having to create two questions for everything is not very user-friendly for typical survey creator

What is the roadmap for 2.1 anyway? I keep hearing about it, but there's not much on the site. Maybe this could use an update :)
docs.limesurvey.org/LimeSurvey+roadmap&highlight=2.1

I totally agree that the two question solution is not the best case, but most surveys are not that complex and thus you can use the assessment feature for most of the simple stuff.

Nevertheless, if you have a good idea on how we can easily mass-add equations to Limesurvey questions, please write a proposal we can discuss.

As for the roadmap: A first Limesurvey 2.1 alpha release is planned for end of January. As so often, my guess would be that it will be February for a first version and maybe April/May for the stable release (just guessing).

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Aw: Expression Manager: Nested Equations? 3 years 8 months ago #90526

  • Fred
  • Fred's Avatar
  • Offline
  • Expert Lime
  • Posts: 147
  • Thank you received: 5
  • Karma: 3
Yes, not the best.. BUT it does work! (Thank you Tom)

Mazi, if you click on my karma button so that it will finally go above zero, then I will think about this equations issue!
The administrator has disabled public write access.

Aw: Expression Manager: Nested Equations? 3 years 8 months ago #90527

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5984
  • Thank you received: 368
  • Karma: 260
:-)

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.267 seconds
Imprint                   Data Protection Statement                  Revocation information and revocation form