Here is a simple way to do this:
// First declare total and count before the loop
$total = 0;
$count = 0;
foreach($posts as $post)
{
if(get_field('prod_fi')){ // If we have a value add it to the total and count it
$total += get_field('prod_fi');
$count++;
}
}
echo 'Count: '. $count;
echo 'Total Sum: '. $total;
echo 'Average: '.($total / $count); // To get the average
EDIT:
In your case, where you have the $prod_query loop, hope this makes more sense 🙂
// Declare total and count before loop
$factorTotal = 0;
$factorCount = 0;
while ( $prod_query->have_posts() ) : $prod_query->the_post();
$factorI = get_field('prod_fi');
if($factorI){ // Only if it exists
$factorTotal += $factorI; // Add it
$factorCount++; // Count it
} // end if
endwhile;
echo 'Count: '. $factorCount;
echo 'Total Sum: '. $factorTotal;
echo 'Average: '.($factorTotal / $factorCount);