Skip to main content
Participant
Jul 31, 2025 6:55 PM UTC
Answered

Addition depending on column values

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

    try67
    try67Correct answer
    Community Expert
    Jul 31, 2025 10:23 PM UTC

    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.

     

    3 replies

    try67
    Community Expert
    try67Community ExpertCorrect answer
    Community Expert
    Jul 31, 2025 10:23 PM UTC

    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.

     

    Translate
    fuma_3655Author
    Participant
    Aug 1, 2025 7:10 AM UTC

    @try67 Thank you so much. Works perfect.

    Translate
    kglad
    Community Expert
    Community Expert
    Jul 31, 2025 7:18 PM UTC

    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">
    Translate