Skip to main content
Participating Frequently
May 8, 2023
Question

How to combine values in one field when two other fields match

  • May 8, 2023
  • 1 reply
  • 4856 views

I am trying to make a form that arranges $ values when two fields match. The form has multiple rows (12 rows max) that calculate a $ value. Then at the end of each row, I have a drop-down (dropdown1) where you can select a fund source; FJC-HT, ARA-JC, and CB Cap are some examples.

 

At the bottom of the form, I want a cumulative total of the $ values for each selected fund source. I have another drop-down (dropdown2)with the same options as drowpdown1. I want to combine the 4 values of each row when these two drop-downs match. So if 3 rows have FJC-HT selected, I want the combined $ value of each row with FJC-HT in one field box next to dropdown2. Then if other sources are selected, they will be combined at the bottom respectively.

This topic has been closed for replies.

1 reply

try67
Community Expert
Community Expert
May 8, 2023

You can use something like this code as the custom Calculation script of the first total field you've described:

 

var total = 0;
for (var i=1; i<=12; i++) {
	if (this.getField("dropdown"+i).valueAsString=="FJC-HT") {
		total+=Number(this.getField("amount"+i).valueAsString);
	}
}
event.value = total;

 

Adjust the field names and text strings as needed.

Participating Frequently
May 12, 2023

I appreciate your support. I tried your suggested coding, but it doesn't produce the desired effect after applying my field names. I attached an image of the form I am working with to help better describe what I am hoping to achieve.

 

When an option is selected in "f1" - "f12", I want those options to be populated in fields "f1a" - "f12a", but I want the selections in "f1" - "f12" that are the same to combine in "f1a" - "f12a". Then I want the $ values in field "a1" - "a12" to follow the selected "f1" - "f12" options to the field next to matching "f1a" - "f12a"

 

So if, for example, "FJC-HT" is selected as an option, let's say "f1" "f2" and "f3". and its "a" values are $12, $3.75, and $5, respectively. I want "f1a" at the bottom to populate with "FJC-HT," and I want "s1" to show the combined $ value of the  "a"s. Then if other options are selected, I want them to match, and populated to "f2a" and on as needed.

Participating Frequently
May 12, 2023

Press Ctrl+J to open the JS Console and you'll see an error message appear after you edit the value of any field. I also don't see where you applied the code I provided...


The copy I provided was a code-free version. But I was testing your provided code on the first "sub" box of the bottom part of the form. If you are looking the Field names, its the one labeled "s1"