Skip to main content
September 25, 2021
Question

2 separate problems: Find Minimum and a count from a range of numbers while ignoring blanks.

  • September 25, 2021
  • 2 replies
  • 694 views

I've got two cells:  First is called:  MINA.   The second cell is called:  CNTA.

I've got one column of numbers:  Cells are named SR-1, SR-2, SR-3, SR-4....SR-31.

 

I need a calculation that finds the minimum value in the range[SR-1:SR-31] that I can use in the "MINA" cell.  This calculation needs to ignore blanks because not all cells in this range may contain data.

 

I need a second calculation that counts the number of cells with data in the range[SR-1:SR-31] that I can use in the "CNTA" cell.  This calculation also needs to ignore blanks for the same reason.

 

I needed an average calculation as well and managed to get that to work, for reference, here is that calculation:  This calculation was typed in my "AVGA" cell.  This one works great with no problems!

-----------------------

// Initialize variables

var i, v, num = 0, sum = 0;

// Loop through the input fields

for (i = 1; i <= 31; i++) {

v = +getField("SR-" + i).value;

if (v !== 0) {

// increment the non-blank/zero field counter

num++;

// add the field value to the running total

sum += v;

    }

}

// Calculate the average

if (num) {

event.value = sum / num;

} else {

// All fields are empty, so set to blank

event.value = "";

}

------------------------

I just can't get anything for a Minimum calculation and for a Count calculation to work.  Remember...they need to be separate calculations--I cannot combine minimum and count in one calculation.

 

Thanks in advance anyone who can help!!

This topic has been closed for replies.

2 replies

Nesa Nurani
Community Expert
Community Expert
September 25, 2021

Try this for min calculation:

function cMin(x,y) {
return Number(x) - Number(y);}
var min = [];
for( var i=1; i<=31; i++){
if(this.getField("SR-"+i).valueAsString != "")
min.push(Number(this.getField("SR-"+i).value));}
if(min.length != 0){
min.sort(cMin);
event.value = min[0];}
else
event.value = "";

September 25, 2021

Thanks, I just figured it out about five minutes ago and was about to post that I got it.  Appreciate it.  Thanks.

September 25, 2021

Edit the above question:  I just figured out how to do the count so I don't need that anymore.  Now, I only need the minimum calculation.  Adobe's built-in Maximum works great but the build-in Minimum doesn't ignore blanks.  My brain has about had it.