Calculate a field using conditional statement and values from select_one, if relevant

708
2
Jump to solution
09-20-2019 05:33 AM
JulieRoebotham
Esri Contributor

I have a survey that has a host of select_one questions. Each set of questions is categorized, each category has between 1 and 4 questions. The first thing i need to do is find the average score for each category of questions, and then find the total overall average. 

The issue i'm having is that one of the categories has a relevant question. So the user is asked the first select_One question, and then if they select '1' (first option) they move on to the next category. If they select 2,3,or 4 from the first select_One question, they are presented with 3 more questions in that category.

I would like to get the average for that category by using an if statement, but i cant get it to work.

for example: if the answer to question 1 is '1', leave the total for this category as 1, otherwise tally up the answers to all the questions in this category and divide by the total number of questions.

I keep getting an error: Invalid calculate for the bind attached to ${calculatefield}

Here is my example. Field i'm trying to calculate is ${calculatefield}, type is decimal and bind type is decimal.

anyone have any ideas!?

if (selected(${Question1},'1')), number(${Question1}), (number(${Question1})+number(${Question2})+ number(${Question3})+ number${Question4}) div 4
0 Kudos
1 Solution

Accepted Solutions
DougBrowning
MVP Esteemed Contributor

You have an extra ) right after selected in bold

if (selected(${Question1},'1')), number(${Question1}), (number(${Question1})+number(${Question2})+ number(${Question3})+ number${Question4}) div 4

You also never close the first ( in the second part in bold

 (number(${Question1})+number(${Question2})+ number(${Question3})+ number${Question4}) div 4

Any you are missing a ( in the last number

number$MISSING{Question4}) div 4

You are also missing the final ) for the if.

Also you do not have to use selected for a select_one you can just use =

 

My guess is you want this

if(${Question1} ='1', number(${Question1}), (number(${Question1})+number(${Question2})+ number(${Question3})+ number(${Question4})) div 4)

View solution in original post

0 Kudos
2 Replies
DougBrowning
MVP Esteemed Contributor

You have an extra ) right after selected in bold

if (selected(${Question1},'1')), number(${Question1}), (number(${Question1})+number(${Question2})+ number(${Question3})+ number${Question4}) div 4

You also never close the first ( in the second part in bold

 (number(${Question1})+number(${Question2})+ number(${Question3})+ number${Question4}) div 4

Any you are missing a ( in the last number

number$MISSING{Question4}) div 4

You are also missing the final ) for the if.

Also you do not have to use selected for a select_one you can just use =

 

My guess is you want this

if(${Question1} ='1', number(${Question1}), (number(${Question1})+number(${Question2})+ number(${Question3})+ number(${Question4})) div 4)

0 Kudos
JulieRoebotham
Esri Contributor

thank you. that worked. just before my brain was about to explore. not a moment too soon!