# Radio button sum calculation

**URL:** <https://the.fmsoup.org/t/radio-button-sum-calculation/2719>\
**Category:** Questions\
**Tags:** scripting\
**Created:** [January 25, 2022, 10:32am UTC](https://the.fmsoup.org/t/radio-button-sum-calculation/2719 "2022-01-25T10:32:31Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jenyen](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/jenyen/32/1804_2.png) [@Jenyen](https://the.fmsoup.org/u/Jenyen)\
**Post date:** [January 25, 2022, 10:32am UTC](https://the.fmsoup.org/t/radio-button-sum-calculation/2719/1 "2022-01-25T10:32:31Z")

</div>

Using FM 7 and have a repeating radio button of Yes or No. I want to calculate how many yeses (and nos) and show this number to the user. Can someone suggest a script? Must I use Let variables? Any help is appreciated. Thanks again.

---

<div class="post-metadata">

**Author:** ![Bobino](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/bobino/32/194_2.png) [@Bobino](https://the.fmsoup.org/u/Bobino)\
**Post date:** [January 25, 2022, 2:03pm UTC](https://the.fmsoup.org/t/radio-button-sum-calculation/2719/2 "2022-01-25T14:03:31Z")

</div>

I would suggest a matching calc fields with the same number of repetitions. One where you turn Yes to 1, and another where you turn No to 1, for each of those calculated repeating fields you can then use Sum() to get how many Yes or No you got.

You could certainly use a script to get the same result, looping on your field repetitions, but there could be cases where you cannot turn to a script, so I mentioned the calc field option also.

---

<div class="post-metadata">

**Author:** ![Jenyen](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/jenyen/32/1804_2.png) [@Jenyen](https://the.fmsoup.org/u/Jenyen)\
**Post date:** [January 25, 2022, 2:28pm UTC](https://the.fmsoup.org/t/radio-button-sum-calculation/2719/3 "2022-01-25T14:28:27Z")

</div>

Your suggestion sounds very good and effective but I don't understand what you mean by "matching calc fields". When I look it up it talks about importing and matching up the fields (which I am familliar with). I am sure I am just not looking at the right area. So can you elaborate for this beginner? Much appreciated.  
I did try using a sum calculation and a summary type in the defining fields but I think I am missing a step.

---

<div class="post-metadata">

**Author:** ![Bobino](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/bobino/32/194_2.png) [@Bobino](https://the.fmsoup.org/u/Bobino)\
**Post date:** [January 25, 2022, 2:32pm UTC](https://the.fmsoup.org/t/radio-button-sum-calculation/2719/4 "2022-01-25T14:32:23Z")

</div>

I'm sorry for the confusion. I did not mean matching as when doing imports, I meant matching as they will mirror your data field. They are very simply regular calculation fields with as many repetitions as your data field. The calculation should be something like `if( dataField = "Yes" ; 1 ; 0 )`. Because it is a repeating field pointing to another repeating field, FileMaker should resolve the calculation by pairing each repetition. I hope this clarifies.

---

<div class="post-metadata">

**Author:** ![bdbd](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/bdbd/32/620_2.png) [@bdbd](https://the.fmsoup.org/u/bdbd)\
**Post date:** [January 25, 2022, 2:36pm UTC](https://the.fmsoup.org/t/radio-button-sum-calculation/2719/5 "2022-01-25T14:36:39Z")

</div>

I suppose it depends how and when you need this information.

If you need this live, without the need for a find operation, then @Bobino's suggestion to use a calculation makes sense. Be careful as this will be an unstored calculation or a summary field… so the larger the record set, the longer the calculation time.

If you are OK with needing to perform a find to obtain the result, then you need not translate the radio button values into numbers. The found count will give you the value you seek.

Keep in mind there is a third value to your radio buttons: yes; no; no answer (empty). You will want to keep this in mind in your design. If a "no answer" value can't exist, you will need to either have a default value or a validation that barks at the user when committing a record.

Hope this helps.

---

<div class="post-metadata">

**Author:** ![Jenyen](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/jenyen/32/1804_2.png) [@Jenyen](https://the.fmsoup.org/u/Jenyen)\
**Post date:** [January 25, 2022, 2:40pm UTC](https://the.fmsoup.org/t/radio-button-sum-calculation/2719/6 "2022-01-25T14:40:20Z")

</div>

yes it does clarify things...I will try it and get back to you. Thanks so much!

---

<div class="post-metadata">

**Author:** ![Bobino](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/bobino/32/194_2.png) [@Bobino](https://the.fmsoup.org/u/Bobino)\
**Post date:** [January 25, 2022, 2:40pm UTC](https://the.fmsoup.org/t/radio-button-sum-calculation/2719/7 "2022-01-25T14:40:23Z")

</div>

> [@bdbd](#):
>
> Be careful as this will be an unstored calculation

The calculation I'm talking about can be stored and indexed, assuming a repeating field holding data in the same table as the calculation table.

Off course, if you want to calculate total answers of one type for multiple records, this will rely on a summary field and, depending on your found set, may not give you the best performance.

---

<div class="post-metadata">

**Author:** ![FileKraft](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/filekraft/32/1183_2.png) [@FileKraft](https://the.fmsoup.org/u/FileKraft)\
**Post date:** [January 25, 2022, 3:25pm UTC](https://the.fmsoup.org/t/radio-button-sum-calculation/2719/9 "2022-01-25T15:25:57Z")

</div>

sorry just see you are on FMP7 - then the WHILE to be replaced with a relationship  
I don't have .fp7 FMP

here is a simple file without any tricks:  
[RepeatingRadioButton\_FMSoup\_7.fmp12](https://the.fmsoup.org/uploads/short-url/eqc3LItfaaVMK8Cgz8Ki7hgM8Hk.fmp12) (280 KB)

PatternCount ( List ( RepeatingRadioButton\_SelfJoin::RadioButtonVector ) ; "YES" )  
PatternCount ( List ( RepeatingRadioButton\_SelfJoin::RadioButtonVector ) ; "No" )

Relationship to the same record matching Primary Key  
 ![RadioButtonVector](https://canada1.discourse-cdn.com/flex030/uploads/fmsoup/original/2X/b/bdd20e8d7bbb826996cfb250ad6b1235b45f86c3.png)

 ![Pasted Graphic](https://canada1.discourse-cdn.com/flex030/uploads/fmsoup/original/2X/8/89775eab4fe74e209310f1f90f7c59f02243d95d.png)

---

<div class="post-metadata">

**Author:** ![Malcolm](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/malcolm/32/196_2.png) [@Malcolm](https://the.fmsoup.org/u/Malcolm)\
**Post date:** [January 25, 2022, 8:34pm UTC](https://the.fmsoup.org/t/radio-button-sum-calculation/2719/10 "2022-01-25T20:34:09Z")

</div>

Ensuring that everything is done in v7 code is an interesting challenge. Variables don't arrive until v8 - something for you to look forward to @Jenyen 😄 but everything we need seems to be in the v7 toolkit.

I found it very easy to do with some fields, the script is only reporting on what they are calculating.

Step 1. Define the fields

 ![field_defs](https://canada1.discourse-cdn.com/flex030/uploads/fmsoup/original/2X/3/35950528024144e69b9e5da4c3952d0a0b32414e.jpeg)

Step 2. Fields on the layout

You can see that the amounts are easily calculated

 ![layout_display](https://canada1.discourse-cdn.com/flex030/uploads/fmsoup/original/2X/c/c19ba28f3abfbb2e86fdb659700a54e5a17cc6aa.jpeg)

Step 3. A script to display the results

 ![script_for_reps](https://canada1.discourse-cdn.com/flex030/uploads/fmsoup/original/2X/8/8c1fc91c8d8d50bf5bafd7d18f5fe9b7b70915da.jpeg)

---

<div class="post-metadata">

**Author:** ![FileKraft](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/filekraft/32/1183_2.png) [@FileKraft](https://the.fmsoup.org/u/FileKraft)\
**Post date:** [January 25, 2022, 9:15pm UTC](https://the.fmsoup.org/t/radio-button-sum-calculation/2719/11 "2022-01-25T21:15:46Z")

</div>

You nailed it @Malcolm list function was not available in FMP7.

---

<div class="post-metadata">

**Author:** ![steve\_ssh](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/steve_ssh/32/160_2.png) [@steve\_ssh](https://the.fmsoup.org/u/steve_ssh)\
**Post date:** [January 25, 2022, 11:18pm UTC](https://the.fmsoup.org/t/radio-button-sum-calculation/2719/12 "2022-01-25T23:18:19Z")

</div>

So fascinating -- It was a trip down memory lane seeing the screenshot of field definitions in @Malcolm's post. There was a time when I had solutions with lots of fields like that...

---

<div class="post-metadata">

**Author:** ![Jenyen](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/jenyen/32/1804_2.png) [@Jenyen](https://the.fmsoup.org/u/Jenyen)\
**Post date:** [January 26, 2022, 7:10am UTC](https://the.fmsoup.org/t/radio-button-sum-calculation/2719/13 "2022-01-26T07:10:33Z")

</div>

Brilliant! Thanks so much - this is exactly what I was looking for.  
I know it is a very old version, so I appreciate it all the more 🙂

---

<div class="post-metadata">

**Author:** ![Jenyen](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/jenyen/32/1804_2.png) [@Jenyen](https://the.fmsoup.org/u/Jenyen)\
**Post date:** [January 26, 2022, 7:14am UTC](https://the.fmsoup.org/t/radio-button-sum-calculation/2719/14 "2022-01-26T07:14:11Z")

</div>

Totally appreciate the effort and the link! Thanks.

---

<div class="post-metadata">

**Author:** ![Kirk](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/kirk/32/2197_2.png) [@Kirk](https://the.fmsoup.org/u/Kirk)\
**Post date:** [February 5, 2022, 7:55pm UTC](https://the.fmsoup.org/t/radio-button-sum-calculation/2719/15 "2022-02-05T19:55:03Z")

</div>

Suggest avoiding repeating fields for anything that stores data. Use a child table instead.  
Repeating fields are painful to manage data and might be best sequestered to transient UI information.

---

<div class="post-metadata">

**Author:** ![Jenyen](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/jenyen/32/1804_2.png) [@Jenyen](https://the.fmsoup.org/u/Jenyen)\
**Post date:** [February 5, 2022, 9:46pm UTC](https://the.fmsoup.org/t/radio-button-sum-calculation/2719/16 "2022-02-05T21:46:11Z")

</div>

LOL - Everyone says this about repeating fields 🙂 I agree with you when it comes to major data storage...I'm just using them for something very simple and manageable. In future versions does FM develop this feature so it can be better used? I am using v7.

---

<div class="post-metadata">

**Author:** ![Kirk](https://yyz2.discourse-cdn.com/flex030/user_avatar/the.fmsoup.org/kirk/32/2197_2.png) [@Kirk](https://the.fmsoup.org/u/Kirk)\
**Post date:** [February 5, 2022, 10:42pm UTC](https://the.fmsoup.org/t/radio-button-sum-calculation/2719/17 "2022-02-05T22:42:35Z")

</div>

In this area, nothing has changed since v7; repeating fields are a legacy construct that the relational structure has all but replaced, and not expecting to see any enhancements to repeating fields.

The one place I use them is to populate a button bar segment set. Nothing stored, just UI stuff.
