You will have to use a custom JavaScript, which will allow you to detect which fields are empty and ignore them if they are. For example:
// Initialize variables
var num = 0;
var sum = 0;
// Loop through the input fields
for (var i = 1; i < 5; i++) {
var f = getField("text." + i);
if (f.valueAsString) {
// increment the non-blank field counter
num++;
// add the field value to the running total
sum += +f.value;
}
}
// Calculate the average
if (num) {
event.value = sum / num;
} else {
// All fields are empty, so set to blank
event.value = "";
}
This code assumes the fields are named "text.1", "text.2", ..."text.4", so change to match your field names