How to get a count of fields with same choice selected on a form?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 11:57 AM
Hi Friends,
I am working on a requirement to do percentage calculation out of the choice field values selected. I need to get the count of all the fields with choice selected as N/A and I want to use a business rule for this. If I can get this count, I can get do average and also percentage calculation.
I have tried to find solution in our community but failed. I haven't worked on such count before so please shed some light on how to achieve this.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 12:41 PM
There are a number of ways to do this but probably the best is to use a GlideAggregate.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2023 07:37 PM
Hi Drew,
What I am looking for is I have a total percentage field on the form and also choice fields with N/A as one of the choice. I want to get the no. of fields on the current record whose choice is selected as N/A so that I can avoid them from percentage calculation. let's say out of 10 choice fields, 5 are N/A, in this case I want to do % calculation only for 5 fields. For that I need to get the fields that were answered as N/A.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 06:51 AM
Ok so you want to do this on a per record basis and not over all for the table. So for your example with 10 choice fields and 5 are N/A you would like your "% Filled" field to show 50%? If that is correct then just use a BR to calculate it something like this
//This code assumes that the value for the "N/A" selection is a blank string.
var count = 0;
if(!current.CHOICE_FIELD1){
count += 1;
}
if(!current.CHOICE_FIELD2){
count += 1;
}
if(!current.CHOICE_FIELD2){
count += 1;
}
//.....
if(!current.CHOICE_FIELD10){
count += 1;
}
//You may want to do some rounding here
current.setValue("% FIELD", (count / 10 * 100));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2023 06:58 AM - edited 04-12-2023 07:04 AM
Hi Drew,
That's right on a per record basis. My choice field values are 'N/A, 0, 1, 2, 3'. So out of 10 fields if 5 of them are N/A answered then we should not consider those 5 fields from 100% calculation. So in this example, it will be (sum of choice value of rest five fields)/5*100
Also I am storing the choice field values as below to have accurate % calculation,
If 0 selected, then the value is 0.25
1 -> 0.5
2 -> 0.75
3 -> 1.0