Your code will be simpler with CASE
formulas. With a picklist, though, you first have to get the TEXT
of the field value.
FLOOR((
CASE(TEXT(Picklist1__c), "Hot", 3, "Warm", 2, "Cold", 1, 0) +
CASE(TEXT(Picklist2__c), "Hot", 3, "Warm", 2, "Cold", 1, 0) +
CASE(TEXT(Picklist3__c), "Hot", 3, "Warm", 2, "Cold", 1, 0)
)/3)
Some sample input/output combos:
"Hot" + "Warm" + "Cold" = 2
"Hot" + "Hot" + "Hot" = 3
"Warm" + "Warm" + Cold" = 1
"Hot" + "Unknown" + "Unknown" = 1
If you want to only count the specified values above against the average, I would create a separate formula called Rating_Count__c
.
IF(NOT(ISPICKVAL(Picklist1__c, "")), 1, 0) +
IF(NOT(ISPICKVAL(Picklist2__c, "")), 1, 0) +
IF(NOT(ISPICKVAL(Picklist3__c, "")), 1, 0)
The reason this needs to be a separate formula is to avoid divide by zero errors. Now you can modify the initial formula as follows:
IF(Rating_Count = 0, NULL, FLOOR((/*sum*/)/Rating_Count__c)
Best Answer
A basic solution for the formula would be
You can add logic to test if Custom_Field_1 is blank and leave the formula field blank in that instance too if necessary.