Select to view content in your preferred language

# Using indexed-repeat in an if() function

750
2
09-06-2023 05:34 PM
Occasional Contributor

Hello all,

I am trying to use the indexed-repeat function to return a value from a repeat when PASS/FAIL-oriented repeat's own index isn't 1. The context for this is that I am working with calculated values that correspond to specific structure heights, so for the span between the first elevation measurement and the ground, I need a zero in the math.

This is the snippet of what I am working with, consisting of rows from A (type) to S (bind::type):

 A B C D E F G H I J K L M N O P Q R S begin repeat pt_passfail_s

Pass/Fail By Guy Level

compact integer condition_index Get repeat index of this condition assessment hidden position(..) integer condition_index_m1 Subtract 1 from condition index hidden \${condition_index}-1 calculate lower_elevation Lower elevation: if(\${condition_index}=1,0,indexed-repeat(\${pt_guy_level_height}, \${guy_elevations_s}, \${condition_index_m1})) integer calculate upper_elevation Upper elevation: indexed-repeat(\${pt_guy_level_height}, \${guy_elevations_s}, \${condition_index}) integer calculate distance_between Calculate distance between elevations \${upper_elevation} - \${lower_elevation} integer note Distance between elevations \${condition_index} (\${lower_elevation}') and \${condition_index_m1} (\${upper_elevation}'): \${distance_between} calculate lower_twist Lower twist: if(\${condition_index}=1,0,indexed-repeat(\${pt_calcs_twist_alpha}, \${pt_calcs_s}, \${condition_index_m1})) decimal calculate upper_twist Upper twist: indexed-repeat(\${pt_calcs_twist_alpha}, \${pt_calcs_s}, \${condition_index}) decimal calculate twist_between Calculate twist between elevations \${upper_twist} - \${lower_twist} decimal calculate twist_per_ten Get divisor for twist per ten feet and compute degrees twist per ten feet (\${twist_between} div (\${distance_between} div 10)) decimal note Twist between elevations \${condition_index} (\${lower_twist}˚ at \${lower_elevation}') and \${condition_index_m1} (\${upper_twist}˚ at \${upper_elevation}'): \${twist_between}˚ note Average twist per ten feet between elevations \${condition_index} and \${condition_index_m1}: \${twist_per_ten}˚ note FAIL: EXCEEDS 0.5˚ TWIST / 10'! \${twist_per_ten} > 0.5 note PASS! \${twist_per_ten} <= 0.5 calculate lower_plumb Lower plumb: if(\${condition_index}=1,0,indexed-repeat(\${pt_calcs_plumb_r}, \${pt_calcs_s}, \${condition_index_m1})) decimal calculate upper_plumb Upper plumb: indexed-repeat(\${pt_calcs_plumb_r}, \${pt_calcs_s}, \${condition_index}) decimal calculate plumb_between Calculate plumb between elevations \${upper_plumb} - \${lower_plumb} decimal note Plumb between elevations \${condition_index} (\${lower_plumb}" at \${lower_elevation}')and \${condition_index_m1} (\${upper_plumb}" at \${upper_elevation}'): \${plumb_between}" note FAIL: OUT-OF-PLUMBNESS EXCEEDS 0.25% OF \${distance_between}'! \${plumb_between} > (\${distance_between} div 400) note PASS! \${plumb_between} <= (\${distance_between} div 400) end repeat pt_passfail_s

This code causes a TypeError for all of my lower_<quantity> terms, and I am not sure why. I believe my if() functions in those rows are constructed correctly, and I have triple-checked that those rows have their bind::type column set to integer. Basically, if the pass/fail repeat is displaying the first record, lower_<quantity> needs to be 0 in each case. On every successive record, it needs to be the value that was upper_<quantity> in the previous record. I thought I accounted for this with my condition_index and condition_index_m1 rows.

I've never tried using the indexed-repeat() function as the "else" component of an if() function, but I don't see why it wouldn't work. Am I missing something about the data type returned by ndexed-repeat()?

Any thoughts or solutions would be greatly appreciated. Thanks!

P.S. These cells are coming from a "recipe book" I keep for modular survey-building. Therefore I can't really post the XLS file here because there would be a pretty significant amount of stuff irrelevant to this particular issue, but I can come up with something in DMs if you are willing to help!

1 Solution

Accepted Solutions
MVP Esteemed Contributor

Why are your bind::type values integer when it should be int.  There should be a drop down with those options.  You can also now use integer as the type and a hidden appearance.

I am also wondering if it will get mad on the first record since then condition_index_m1 would give a negative value?

In your indexed repeat your ask for a field \${pt_guy_level_height} but I do not see it in this list at all?  Where is this field?

Just some ideas

2 Replies
MVP Esteemed Contributor

Why are your bind::type values integer when it should be int.  There should be a drop down with those options.  You can also now use integer as the type and a hidden appearance.

I am also wondering if it will get mad on the first record since then condition_index_m1 would give a negative value?

In your indexed repeat your ask for a field \${pt_guy_level_height} but I do not see it in this list at all?  Where is this field?

Just some ideas

Occasional Contributor

Ahh Doug, brilliant as always! The main issue was indeed my use of integer instead of int, silly me. You were also apparently correct about an issue occurring with the first record, though no obvious error was caused; instead, no values were populating. I was able to get around this by finagling some of the calculation expressions, as in the following example:

 A B C D E F G H I J K L M N O P Q R S calculate lower_elevation Lower elevation: indexed-repeat(\${pt_guy_level_height}, \${guy_elevations_s}, \${condition_index_m1}) \${condition_index}>1 int calculate upper_elevation Upper elevation: indexed-repeat(\${pt_guy_level_height}, \${guy_elevations_s}, \${condition_index}) int calculate distance_between Calculate distance between elevations if(\${condition_index}>1,(\${upper_elevation}-\${lower_elevation}),\${upper_elevation}) int

Finally, the \${pt_guy_level_height} field lives up in a repeat that happens several hundred rows higher in my 'Recipe' XLS form, as it applies to a variety of my survey modules - hence why it wasn't included here.

Thanks again for the solid eyeballs and suggestions!