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
-
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
endBut...
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
-
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
endYou 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.
-
or simply a formula(Score) field with : number(Rating)
assuming that the choice values are numbered from 1 "Not Much" ...... 3 "Significant"
Steven
-
Thanks so much for these speedy replies and options which will help me in the future too. I'll get on and implement....
-
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
- 3 yrs agoLast active
- 5Replies
- 389Views