0

Stuck on simple multiple if/else

Hello,

I am trying to update a formula field 'Score' with values 1, 2, or 3 based on corresponding ratings from choice field 'Rating':

if Rating = "Not much" then
= "1"
else
if Rating = "Good" then
= "2"
else
if Rating = "Significant" then
= "3"
end
end
end

 

The formula is acdepted wiorthout syntax errors but the score field does not populate.

 

Sure I am overlooking something basic. Please help.

 

Regards,

 

Robert

5 replies

null
    • John_Halls
    • 2 yrs ago
    • Reported - view

    Hi Robert

     

    Just a couple of tweaks. To use the text of a choice field in a formula you need to use text(Rating) and then as it's in a formula field just use the value without the equals sign. So it all becomes

    if text(Rating) = "Not much" then
    "1"
    else
    if text(Rating) = "Good" then
    "2"
    else
    if Text(Rating) = "Significant" then
    "3"
    end
    end
    end

     

    But...

     

    Each item in a choice fields has a value so if they are set up in that order you can just use number(Rating) in your formula field, and if it has to be as text as in your code then use text(number(Rating)).

     

    Regards John

    • Fred
    • 2 yrs ago
    • Reported - view

    Hi Robert -

     

    Since Rating is a choice field, Ninox by default uses the number assigned to each choice. So if the choice 1 is "Not much" and choice 2 is "Good" and choice 3 is "Significant" then you can change your code to:

     

    if Rating = 1 then
    = 3
    else
    if Rating = 2 then
    = 2
    else
    if Rating = 3 then
    = 3
    end
    end
    end

    You also don't need quotes around numbers.

     

    If you want to use text results in Ratings then you need to change to:

     

    if text(Rating) = "Not much" then
    = 1
    else
    etc.

     

    Good luck and let us know how it goes.

    • Ninox partner
    • RoSoft_Steven.1
    • 2 yrs ago
    • Reported - view

    or simply a formula(Score) field with : number(Rating)

    assuming that the choice values are numbered from 1 "Not Much" ...... 3 "Significant"

    Steven

    • Robert_Fitzmaurice
    • 2 yrs ago
    • Reported - view

    Thanks so much for these speedy replies and options which will help me in the future too. I'll get on and implement....

    • Danjamesmedia
    • 2 yrs ago
    • Reported - view

    The best practice is to use "switch case" rather than nested ifs.

     

    switch FieldName do

    case ValueID: OutputtedValue

    (repeat last line for each ID)

    default: OutputtedValue

    end

     

    so in your case:

     

    switch Rating do

    case 1: 1

    case 2: 2

    case 3: 3

    end

Content aside

  • 2 yrs agoLast active
  • 5Replies
  • 373Views