Welcome to the LimeSurvey Community Forum

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

Equation - Multiply two fields

  • stemate1988
  • stemate1988's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 11 months ago #134072 by stemate1988
Equation - Multiply two fields was created by stemate1988
Morning Guys,

Been scratching my head over this for last couple of days and cant work out exactly how to do it. Been looking at relevance equations and can't seem to work it out.
Basically, I want an equation field or a display text field question type to display an amount of two previous numerical input fields multiplied together (which also write back to the db).

E.g
Q1. Fence Type (dropdown box) subquestion 1 is selected
Q2. Linear Metres: 5 is input (Numerical input - static)
Q3. Unit cost: £9.99 (amount automatically displayed in dropdown to be selected based on condition with Q1)
Q4. The total net cost: ((Q2)*Q3A1 or Q3A2 or Q3A3) - This is the part I cant figure out, as you can see there are OR operators in this equation if a different unit cost and fence type had been selected)

I hope I explained this well enough and someone can point me in the right direction

Much appreciated
Stephen
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
7 years 11 months ago #134082 by tpartner
Replied by tpartner on topic Equation - Multiply two fields
You can use hidden equation type questions to store the unit and total costs.

- Q1 - "Fence Type" (dropdown box)

- Q2 - "Linear Metres": (numerical input)

- equation1 - (equation question) - stores the unit cost with an equation using nested IF statements like this (line-breaks added for clarity)
Code:
{if(Q1 == 'A1', '9.99', 
  if(Q1 == 'A2', '10.99', 
    if(Q1 == 'A3', '11.99', 
      if(Q1 == 'A4', '12.99', '')
    )
  )
)}

- equation2 - (equation question) - stores the total cost with an equation like this:
Code:
{equation1 * Q2}

- display1 - "The total net cost: {equation2}"

Sample survey attached:

File Attachment:

File Name: limesurvey...9-10.lss
File Size:16 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: stemate1988
The topic has been locked.
  • stemate1988
  • stemate1988's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
7 years 11 months ago #134099 by stemate1988
Replied by stemate1988 on topic Equation - Multiply two fields
brilliant, thanks alot for this.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose