Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Calculations based on responses

  • Reconnect
  • Reconnect's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 9 months ago #223257 by Reconnect
Calculations based on responses was created by Reconnect
Please help us help you and fill where relevant:
Your LimeSurvey version: 5.2.7
Own server or LimeSurvey hosting: LimeSurvey
Theme:

==================
This should not be complex but I am stumped, possibly because I haven't been able to open the Expression Manager despite perusal of the Manual. I can do some things within {}, like INSERTANS. In a current survey I have a multiple short text question that requires integer responses. I also have a text display question that displays text along the lines of: 'The total of your responses is X'. What is the syntax for X if in needs to be the total of all the responses to the multiple short text question? Do I have to use an Equation question? How do I do this? Then do I use INSERTANS with the Equation question identifier?
Many thanks
Jonathan
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 9 months ago #223258 by Joffm
Replied by Joffm on topic Calculations based on responses
Hi,

because I haven't been able to open the Expression Manager 

There is nothing to OPEN.
You script your desired equation using the implemented functions.
[url] manual.limesurvey.org/ExpressionScript_-...mplemented_functions [/url]
Therefore it is renamed from "Expression Manager" in versions 3.x. and before to "ExpressionScript".

And INSERTANS was used before Expression Manager/Script was included in LimeSurvey. So, forget it.

And your question is answered here
[url] manual.limesurvey.org/ExpressionScript_-...#.22That.22_variable [/url]

So, you have to decide.
If you only want to display this sum it it sufficient to write in a question of type "text display", in the end message or whereever
The total of your responses is {sum(that.Q1.NAOK)}

If you want to store this value in your dataset you use a questio of type "equation"  (eqSum) with only this {sum(that.Q1.NAOK)}
Later you may refer to this question like
The total of your responses is {eqSum}

By the way:

I have a multiple short text question that requires integer responses.

Why didn't you use a multiple numeric question instead?

Joffm

Here you find some sample surveys using ExpressionScript
[url] manual.limesurvey.org/ExpressionScript_sample_surveys [/url]

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • Reconnect
  • Reconnect's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
2 years 9 months ago #223260 by Reconnect
Replied by Reconnect on topic Calculations based on responses
Joffm,

This is so helpful. I think I finally understand how it works (and the syntax looks like php, which I did a little with some years ago - but I've got rusty with scripting, I'm a social science researcher). I've started replacing the INSERTANS that I have too (and can now trim uneccessary whitespace etc.). And I've changed the multiple short text to multiple numeric.

My questions were answered and I think I've learnt a lot. Thank you.

Jonathan
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose