Skip to main content
Participant
July 31, 2025
Answered

Addition depending on column values

  • July 31, 2025
  • 2 replies
  • 199 views

In Adobe Acrobat Pro I am trying to add fields depending on different column. I have no idea where to start. I already tried to use the Sum fuction of Adobe but here I can only select fields. Can someone please help me here? Maybe JavaScript or another solution?

Tha Table below shows what i am trying to achieve.

Col1 Col2
20A
30B
40C
50A
60B

Col1 ist contains number fields Col2 contains only one Char e.g. A, B or C.

I am trying to add all values Col1 where value of col2 is for example A.

 

Thanks

    Correct answer try67

    Let's say the fields are named Col1_1 to Col1_5 and Col2_1 to Col2_5. You can use this code as the custom calculation script of the field you want to sum up all of the "A" values:

     

    var total = 0;
    for (var i=1; i<=5; i++) {
    	if (this.getField("Col2_"+i).valueAsString=="A") {
    		total+=Number(this.getField("Col1_"+i).valueAsString);
    	}
    }
    event.value = total;

     

    You can easily modify the code to add up the "B", "C", etc. values.

     

    2 replies

    try67
    Community Expert
    try67Community ExpertCorrect answer
    Community Expert
    July 31, 2025

    Let's say the fields are named Col1_1 to Col1_5 and Col2_1 to Col2_5. You can use this code as the custom calculation script of the field you want to sum up all of the "A" values:

     

    var total = 0;
    for (var i=1; i<=5; i++) {
    	if (this.getField("Col2_"+i).valueAsString=="A") {
    		total+=Number(this.getField("Col1_"+i).valueAsString);
    	}
    }
    event.value = total;

     

    You can easily modify the code to add up the "B", "C", etc. values.

     

    fuma_3655Author
    Participant
    August 1, 2025

    @try67 Thank you so much. Works perfect.

    kglad
    Community Expert
    Community Expert
    July 31, 2025

    in the future, to find the best place to post your message, use the list here, https://community.adobe.com/

    p.s. i don't think the adobe website, and forums in particular, are easy to navigate, so don't spend a lot of time searching that forum list. do your best and we'll move the post (like this one has already been moved) if it helps you get responses.



    <"moved from using the community">