Select to view content in your preferred language

Multiplication with a calculation

113
2
a week ago
Phein62
Emerging Contributor

I'm doing calculations in a Repeat.   The CrackLength calculation works fine.  The SpallArea doesn't.  I'm sure it has something to do with the syntax of the calculation for the hidden field SpallArea.  What I need is the product of the Length times the Width for areas of spalling, i.e., SpallArea:

 

 

begin group            Summary            Summary of Cracks

decimal                     TotalLength       Total Length of Cracks                 sum(${CrackLength})

decimal                     TotalArea           Total Area of Spalling                  sum(${SpallArea})

end group

The repeat looks something like:

begin repeat        Surface                      Surface Condition

begin group         Surface1                      </>

decimal                  Length                     Length

decimal                  Width                       Width

select_one           DamageType           Type             [NOTE:  This would be cracking, spalling, etc.]

select_one           Recommendation    Recommendation   [NOTE: This would be Monitor, Repair, No Action]

hidden                   CrackLength                 Calculation: if(selected(${DamageType},'cracking') and selected(${Recommendation},'Repair'),${Length},0)           bind::type: decimal

hidden           SpallArea                              Calculation: if(selected($(DamageType),'spalling') and selected(${Recommendation},'Repair'), ${Length*Width}, 0)   bind::type decimal            

end group

end repeat

0 Kudos
2 Replies
Phein62
Emerging Contributor

A colleague stopped by and was looking over my shoulder, and said I should create another hidden field, call it RawSpallArea, add a calculation for that field ${Length}*${Width}, and then reference that in SpallArea like so:

 Calculation: if(selected($(DamageType),'spalling') and selected(${Recommendation},'Repair'), ${RAwSpallArea}, 0)   bind::type decimal         

 

I'm not sure how elegant that is, but it works.   

0 Kudos
ChristopherCounsell
MVP Regular Contributor

${length*width} is trying to reference a field called 'length*width' that doesn't exist. The correct format is ${length} * ${width}. This finds two fields 'length' and 'width' and multiplies them using *.

You should not need to use an 'if' statement within the calculation. You calculation is basic. It should just be ${length}*${width}.

Move the if statement to the relevant column. End result is:

  • Users select type
  • Users enter length
  • Users enter width (relevant to a type requiring width)
  • Calculations (relevant to type using if statements, basic calculations)

Using relevant means your users will only see the questions they need. The calculations will only trigger when relevant, and you don't need to combine the if statements within the calculation itself.

https://community.esri.com/t5/arcgis-survey123-blog/using-formulas-in-survey123/ba-p/898169

https://community.esri.com/t5/arcgis-survey123-blog/survey123-tricks-of-the-trade-hidden-relevant-an...

0 Kudos