AnsweredAssumed Answered

Survey123, 2 fields calculate off each other. Which direction they are calculated is dependent on a select_one

Question asked by mosquitogis on Jan 2, 2020
Latest reply on Jan 3, 2020 by dougbrowning

The scenario is this.  We are treating using granular larvicides/pesticides. The field user estimates acreage and enters it.  They then weigh their bag before treating, then after treating they weigh it again to see how much pesticide was used.  To determine the rate in which they discharged the pesticide, they put the amount of pesticide dispersed in the Amount field and choose to calculate it by Amount.  It calculates their rate and displays that calculated rate in the Rate Field.


However there are times where they can't weigh it before and after, and so must make a judgement on the rate they put the pesticide out instead of going on the amount.  In this case, I would like them to say they are going to calculate using Rate (instead of amount) and have them enter their rate into the Rate field and it calculates and displays the amount of pesticide used in the Amount field.  


And both fields need to be visible to the user.


Here is a basic setup of what I am trying to accomplish:

Form--- 3 numeric fields and 1 "Select One" field.




Calculate method

   Select one

  •       Rate
  •       Amount








 Rate is to Calculate via if(selected(${RateOrAmount}, 'Amount'), ${Amount} div ${Acres}, '0')


 Amount is to Calculate via if(selected(${RateOrAmount}, 'Rate'), ${Rate} * ${Acres}, '0')




However, this throws an error.


I am pretty sure, the problem is in the 'else' portion.  Since I am defining the else to be 0 (as one usually does) then if Rate was to be chosen as the calculation method, the Rate field would find it shouldn't follow the if/then statement and and instead go 'else' and place a 0 in the field, which then affects the Amount field that was trying to legitimately calculate based on what was entered into the Rate field (That was just ripped out from underneath itself).


If I am to remove either If/Then and run it, it has no issues.  But if both exist, It will not run.


Anyone know how to make it so that instead of defining it as 0, I can just say, "Then don't worry about it.  Just sit and be happy" or something.


Or have a different idea on how to set this up so it will be successful?  Thanks.  Hopefully this makes sense and is clear.