Return a value if another cell has one of many values
I'm not sure if the IF function is even the right one to start, but the question is:
I have a cell Y8 and it displays different numbers:
0,5,10,15,20,35,50
I need to type a formula that returns a text value, but I have 4 arguments.
I need it to return the following:
If it's...
- ...less then 10 = Level 1.
- ...between 10-19 = Level 2.
- ...20:29 = Level 3
- ...30+ = Level 4.
Using the IF function I only managed to get a return value of either Level 1 or Level 2 depending on the number which is constantly changing.
I have used the following formula:
=IF(Y8<=9, "Level 1", IF(Y8<="10:19", "Level 2"))
Any ideas on what formula I can use to get a return value for all 4 arguments?
microsoft-excel worksheet-function
add a comment |
I'm not sure if the IF function is even the right one to start, but the question is:
I have a cell Y8 and it displays different numbers:
0,5,10,15,20,35,50
I need to type a formula that returns a text value, but I have 4 arguments.
I need it to return the following:
If it's...
- ...less then 10 = Level 1.
- ...between 10-19 = Level 2.
- ...20:29 = Level 3
- ...30+ = Level 4.
Using the IF function I only managed to get a return value of either Level 1 or Level 2 depending on the number which is constantly changing.
I have used the following formula:
=IF(Y8<=9, "Level 1", IF(Y8<="10:19", "Level 2"))
Any ideas on what formula I can use to get a return value for all 4 arguments?
microsoft-excel worksheet-function
2
I think "cases" is a better term than "argument".
– Acccumulation
Dec 20 '18 at 18:24
add a comment |
I'm not sure if the IF function is even the right one to start, but the question is:
I have a cell Y8 and it displays different numbers:
0,5,10,15,20,35,50
I need to type a formula that returns a text value, but I have 4 arguments.
I need it to return the following:
If it's...
- ...less then 10 = Level 1.
- ...between 10-19 = Level 2.
- ...20:29 = Level 3
- ...30+ = Level 4.
Using the IF function I only managed to get a return value of either Level 1 or Level 2 depending on the number which is constantly changing.
I have used the following formula:
=IF(Y8<=9, "Level 1", IF(Y8<="10:19", "Level 2"))
Any ideas on what formula I can use to get a return value for all 4 arguments?
microsoft-excel worksheet-function
I'm not sure if the IF function is even the right one to start, but the question is:
I have a cell Y8 and it displays different numbers:
0,5,10,15,20,35,50
I need to type a formula that returns a text value, but I have 4 arguments.
I need it to return the following:
If it's...
- ...less then 10 = Level 1.
- ...between 10-19 = Level 2.
- ...20:29 = Level 3
- ...30+ = Level 4.
Using the IF function I only managed to get a return value of either Level 1 or Level 2 depending on the number which is constantly changing.
I have used the following formula:
=IF(Y8<=9, "Level 1", IF(Y8<="10:19", "Level 2"))
Any ideas on what formula I can use to get a return value for all 4 arguments?
microsoft-excel worksheet-function
microsoft-excel worksheet-function
edited Dec 20 '18 at 22:59
Braiam
4,02631851
4,02631851
asked Dec 20 '18 at 11:25
dandan
193
193
2
I think "cases" is a better term than "argument".
– Acccumulation
Dec 20 '18 at 18:24
add a comment |
2
I think "cases" is a better term than "argument".
– Acccumulation
Dec 20 '18 at 18:24
2
2
I think "cases" is a better term than "argument".
– Acccumulation
Dec 20 '18 at 18:24
I think "cases" is a better term than "argument".
– Acccumulation
Dec 20 '18 at 18:24
add a comment |
6 Answers
6
active
oldest
votes
There are two ways you can do this depending on how thorough you want to be.
Personally I prefer the first example:
=IF(Y8<=9, "Level 1", IF(Y8<=19, "Level 2", IF(Y8<=29 "Level 3", "Level 4")))
You don't worry about defining Level 2 as being at least 10 as it is inferred that Y8 has to be greater than 9 by not matching and returning "Level 1".
If you wanted to really thorough and define upper and lower bounds then you could do something like this, it also includes returning a warning/error in case the value in Y8 is not a number:
=IF(Y8<=9, "Level 1", IF(AND(Y8>=10, Y8<=19), "Level 2", IF(AND(Y8>=20, Y8<=29), "Level 3", IF(Y8>=30, "Level 4", "Not a number or some other error"))))
1
Something so simple, but I couldn't get my head round it. Thank you for your help. 1st example does the job!
– dan
Dec 20 '18 at 11:58
1
@dan note that nested IFs can only get so many levels deep. This solution won't scale.VLOOKUPwould be much simpler, and would require zero maintenance, should the thresholds ever need to change.
– Mathieu Guindon
Dec 20 '18 at 15:39
1
"Something so simple" ? @dan I think u misunderstood it.. It is NOT simple.. || It's head-scratching even for a junior programmer when they started to learn recursively call a function. || In your case it is lucky coz the function involved is the basic IF(). If it is a recursive index()+match() , then I don't think it is easily explained. || Either way.. congratulation upon learning this new skill, and making an effort to make (the original) question simple and straightforwardly understandable. ( :
– p._phidot_
Dec 20 '18 at 17:16
The second example returned an error when I tried it. And you can have fewer nesting levels with a binary search:=IF(Y8<20,IF(Y8<10,"Level 1", "Level 2"),IF(Y8<30,"Level 3","Level 4"))
– Acccumulation
Dec 20 '18 at 18:36
cheers Accumulation - added a missing comma to the second code snippet.
– RickyTillson
Dec 21 '18 at 8:20
add a comment |
You can use CHOOSE with MATCH
=CHOOSE(MATCH(Y8,{0,10,20,30}),"Level 1","Level 2","Level 3","Level 4")
If you are really wanting the Level and a number we can do:
="Level " & MATCH(Y8,{0,10,20,30})
This solution scales better than the nested IFs picked by the OP.
– Mathieu Guindon
Dec 20 '18 at 15:43
Nice ! wish I had thought of using MATCH in my answer...
– PeterH
Dec 20 '18 at 15:49
add a comment |
Make a sorted lookup table with the Level corresponding to each threshold:
Value Level
0 1
10 2
20 3
30 4
Now you can use a simple VLOOKUP to get the Level given any Value, and if the thresholds ever need to change, or if new levels need to be added, your VLOOKUP formula doesn't need to change - just maintain the thresholds table, and done.
="Level " & VLOOKUP(theValue, theLookupTable, 2, TRUE)
Note the TRUE argument for the last parameter, making VLOOKUP use an approximate match rather than the typically-used exact match mode. As long as the thresholds are sorted ascending, VLOOKUP will return the Level value for the largest Value that is still smaller than the lookup value.

add a comment |
I like the answer by Scott Craner. However, I thought I would point out some other options.
If you have Excel 2016 or later, your can use the IFS function to simplify the structure of nested IF functions.
=IFS(Y8<10,"Level 1",Y8<20,"Level 2",Y8<30,"Level 3",TRUE,"Level 4")
The way it works is:
- If Y8 is less than 10, it will return "Level 1", otherwise ...
- If Y8 is less than 20, it will return "Level 2", otherwise ...
- If Y8 is less than 30, it will return "Level 3", otherwise ...
- It will return "Level 4"
In the example given in the question, the "level" number increases by one each time the value in Y8 increases by 10. In this special case, it is possible to calculate the level number without using IF.
="Level "&INT(MIN(30,MAX(0,Y8))/10)+1
Note that the question states that any value less than 10 is level 1 and any value greater than 30 is level 4. In order to force negative numbers to be "Level 1" and numbers greater than 39 to be level 4, the formula uses MIN(30,MAX(0,Y8)) instead of Y8.
my personal favorite answer.. nailed it.. nice shoot. || for @dan .. this is a mathematically induced dose on excel formula.. inputOutput pattern matching method.. best the best an algo can get. ( :
– p._phidot_
Dec 20 '18 at 17:22
@p._phidot_ Agree on the soundness of the math-based approach, but disagree that it's the best way to go: it makes an assumption on the data and encodes it into terse math logic. If the assumptions are ever invalidated (e.g. 6 months later, need a level 5 for 50+), then everything needs to be rewritten. Upvoted forIFS, but the math-based approach isn't respecting the original specifications for the upper bound value (i.e. return 4 for 30+), and making it so would involve further complicating the formula, making it encode even more metadata rather than simply reading like the specs.
– Mathieu Guindon
Dec 20 '18 at 18:02
@MathieuGuindon I thoroughly agree that the maths-based approach is not the best one for the general case, the OP would have to consider how set in stone the "10 values per level" pattern is. Thanks for pointing out that I didn't correctly handle the >30 case. I'll correct that (although, as you say, it will make the formula more complicated).
– Blackwood
Dec 20 '18 at 18:14
@MathieuGuindon Thanks for the heads up.. in general case, I'd agree with you. ( : || "the best" statement only goes for me I guess.. with my favorite theme of doing things... may not be the best for others.. || IMHO, if this was a competition, this solution will easily lose.. but , it worth an honorable mention.
– p._phidot_
Dec 21 '18 at 1:07
@p._phidot_ eh, I'm severely biased towards separating logic and data (programmer background, I guess); logic is usually dead-simple, it's the changing data/metadata that complicates things - IMO that's the case here; inlining the array (as in the top-voted answer) works for small sets, but won't scale nicely to e.g. 100 items ...which may or may not be a concern or even a possibility. Full separation of the data (as in mine) can be overkill, but seldom fails to scale and makes maintenance simpler, again just IMO =)
– Mathieu Guindon
Dec 21 '18 at 1:13
add a comment |
Another solution is to create a table holding the lower bounds of your values and using VLOOKUP
table with level values
=VLOOKUP(lookup value, table array, col_index_num,[range lookup])
The last variable in VLOOKUP is "Approximate match" TRUE/FALSE
Choosing the former will have the function attempt to find the "nearest value" with numbers this results in the function looking for any value "lower" than the input in the table. Using 9 as an example the closest result is 0 and will return "level 1".
this method also allows you to increase your options and levels on the fly.
That's... the answer I posted 15 minutes ago.
– Mathieu Guindon
Dec 20 '18 at 15:53
Yeah I was otherwise occupied while typing this. Will upvote yours though.
– Durielblood
Dec 20 '18 at 15:55
2
Yay team-vlookup!
– Mathieu Guindon
Dec 20 '18 at 16:00
2
Welcome to Super User. It isn't uncommon for someone to post a nearly identical solution while you're is working on their own. The intention is that each answer should provide a solution that hasn't already been contributed. In that situation, unless your answer adds something substantive, consider deleting it. It happens to everyone. :-)
– fixer1234
Dec 20 '18 at 16:12
add a comment |
As an alternative to using nested IFs, you can use CHOOSE:
=IF(Y8>30,"Level 4",CHOOSE(MAX(1,ROUNDUP((Y8-1)/10,0)),"Level 1","Level 2","Level 3"))
Where there are only 4 different conditions I would usually use a series of nested IFs, but if you had say 100 conditions, it is a lot easier to use CHOOSE.
That doesn't work at all. Did you try any test values?
– Acccumulation
Dec 20 '18 at 18:42
Re try it, misplaced the bracket around the minus 1
– PeterH
Dec 21 '18 at 7:44
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1386242%2freturn-a-value-if-another-cell-has-one-of-many-values%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
There are two ways you can do this depending on how thorough you want to be.
Personally I prefer the first example:
=IF(Y8<=9, "Level 1", IF(Y8<=19, "Level 2", IF(Y8<=29 "Level 3", "Level 4")))
You don't worry about defining Level 2 as being at least 10 as it is inferred that Y8 has to be greater than 9 by not matching and returning "Level 1".
If you wanted to really thorough and define upper and lower bounds then you could do something like this, it also includes returning a warning/error in case the value in Y8 is not a number:
=IF(Y8<=9, "Level 1", IF(AND(Y8>=10, Y8<=19), "Level 2", IF(AND(Y8>=20, Y8<=29), "Level 3", IF(Y8>=30, "Level 4", "Not a number or some other error"))))
1
Something so simple, but I couldn't get my head round it. Thank you for your help. 1st example does the job!
– dan
Dec 20 '18 at 11:58
1
@dan note that nested IFs can only get so many levels deep. This solution won't scale.VLOOKUPwould be much simpler, and would require zero maintenance, should the thresholds ever need to change.
– Mathieu Guindon
Dec 20 '18 at 15:39
1
"Something so simple" ? @dan I think u misunderstood it.. It is NOT simple.. || It's head-scratching even for a junior programmer when they started to learn recursively call a function. || In your case it is lucky coz the function involved is the basic IF(). If it is a recursive index()+match() , then I don't think it is easily explained. || Either way.. congratulation upon learning this new skill, and making an effort to make (the original) question simple and straightforwardly understandable. ( :
– p._phidot_
Dec 20 '18 at 17:16
The second example returned an error when I tried it. And you can have fewer nesting levels with a binary search:=IF(Y8<20,IF(Y8<10,"Level 1", "Level 2"),IF(Y8<30,"Level 3","Level 4"))
– Acccumulation
Dec 20 '18 at 18:36
cheers Accumulation - added a missing comma to the second code snippet.
– RickyTillson
Dec 21 '18 at 8:20
add a comment |
There are two ways you can do this depending on how thorough you want to be.
Personally I prefer the first example:
=IF(Y8<=9, "Level 1", IF(Y8<=19, "Level 2", IF(Y8<=29 "Level 3", "Level 4")))
You don't worry about defining Level 2 as being at least 10 as it is inferred that Y8 has to be greater than 9 by not matching and returning "Level 1".
If you wanted to really thorough and define upper and lower bounds then you could do something like this, it also includes returning a warning/error in case the value in Y8 is not a number:
=IF(Y8<=9, "Level 1", IF(AND(Y8>=10, Y8<=19), "Level 2", IF(AND(Y8>=20, Y8<=29), "Level 3", IF(Y8>=30, "Level 4", "Not a number or some other error"))))
1
Something so simple, but I couldn't get my head round it. Thank you for your help. 1st example does the job!
– dan
Dec 20 '18 at 11:58
1
@dan note that nested IFs can only get so many levels deep. This solution won't scale.VLOOKUPwould be much simpler, and would require zero maintenance, should the thresholds ever need to change.
– Mathieu Guindon
Dec 20 '18 at 15:39
1
"Something so simple" ? @dan I think u misunderstood it.. It is NOT simple.. || It's head-scratching even for a junior programmer when they started to learn recursively call a function. || In your case it is lucky coz the function involved is the basic IF(). If it is a recursive index()+match() , then I don't think it is easily explained. || Either way.. congratulation upon learning this new skill, and making an effort to make (the original) question simple and straightforwardly understandable. ( :
– p._phidot_
Dec 20 '18 at 17:16
The second example returned an error when I tried it. And you can have fewer nesting levels with a binary search:=IF(Y8<20,IF(Y8<10,"Level 1", "Level 2"),IF(Y8<30,"Level 3","Level 4"))
– Acccumulation
Dec 20 '18 at 18:36
cheers Accumulation - added a missing comma to the second code snippet.
– RickyTillson
Dec 21 '18 at 8:20
add a comment |
There are two ways you can do this depending on how thorough you want to be.
Personally I prefer the first example:
=IF(Y8<=9, "Level 1", IF(Y8<=19, "Level 2", IF(Y8<=29 "Level 3", "Level 4")))
You don't worry about defining Level 2 as being at least 10 as it is inferred that Y8 has to be greater than 9 by not matching and returning "Level 1".
If you wanted to really thorough and define upper and lower bounds then you could do something like this, it also includes returning a warning/error in case the value in Y8 is not a number:
=IF(Y8<=9, "Level 1", IF(AND(Y8>=10, Y8<=19), "Level 2", IF(AND(Y8>=20, Y8<=29), "Level 3", IF(Y8>=30, "Level 4", "Not a number or some other error"))))
There are two ways you can do this depending on how thorough you want to be.
Personally I prefer the first example:
=IF(Y8<=9, "Level 1", IF(Y8<=19, "Level 2", IF(Y8<=29 "Level 3", "Level 4")))
You don't worry about defining Level 2 as being at least 10 as it is inferred that Y8 has to be greater than 9 by not matching and returning "Level 1".
If you wanted to really thorough and define upper and lower bounds then you could do something like this, it also includes returning a warning/error in case the value in Y8 is not a number:
=IF(Y8<=9, "Level 1", IF(AND(Y8>=10, Y8<=19), "Level 2", IF(AND(Y8>=20, Y8<=29), "Level 3", IF(Y8>=30, "Level 4", "Not a number or some other error"))))
edited Dec 21 '18 at 8:19
answered Dec 20 '18 at 11:48
RickyTillsonRickyTillson
1466
1466
1
Something so simple, but I couldn't get my head round it. Thank you for your help. 1st example does the job!
– dan
Dec 20 '18 at 11:58
1
@dan note that nested IFs can only get so many levels deep. This solution won't scale.VLOOKUPwould be much simpler, and would require zero maintenance, should the thresholds ever need to change.
– Mathieu Guindon
Dec 20 '18 at 15:39
1
"Something so simple" ? @dan I think u misunderstood it.. It is NOT simple.. || It's head-scratching even for a junior programmer when they started to learn recursively call a function. || In your case it is lucky coz the function involved is the basic IF(). If it is a recursive index()+match() , then I don't think it is easily explained. || Either way.. congratulation upon learning this new skill, and making an effort to make (the original) question simple and straightforwardly understandable. ( :
– p._phidot_
Dec 20 '18 at 17:16
The second example returned an error when I tried it. And you can have fewer nesting levels with a binary search:=IF(Y8<20,IF(Y8<10,"Level 1", "Level 2"),IF(Y8<30,"Level 3","Level 4"))
– Acccumulation
Dec 20 '18 at 18:36
cheers Accumulation - added a missing comma to the second code snippet.
– RickyTillson
Dec 21 '18 at 8:20
add a comment |
1
Something so simple, but I couldn't get my head round it. Thank you for your help. 1st example does the job!
– dan
Dec 20 '18 at 11:58
1
@dan note that nested IFs can only get so many levels deep. This solution won't scale.VLOOKUPwould be much simpler, and would require zero maintenance, should the thresholds ever need to change.
– Mathieu Guindon
Dec 20 '18 at 15:39
1
"Something so simple" ? @dan I think u misunderstood it.. It is NOT simple.. || It's head-scratching even for a junior programmer when they started to learn recursively call a function. || In your case it is lucky coz the function involved is the basic IF(). If it is a recursive index()+match() , then I don't think it is easily explained. || Either way.. congratulation upon learning this new skill, and making an effort to make (the original) question simple and straightforwardly understandable. ( :
– p._phidot_
Dec 20 '18 at 17:16
The second example returned an error when I tried it. And you can have fewer nesting levels with a binary search:=IF(Y8<20,IF(Y8<10,"Level 1", "Level 2"),IF(Y8<30,"Level 3","Level 4"))
– Acccumulation
Dec 20 '18 at 18:36
cheers Accumulation - added a missing comma to the second code snippet.
– RickyTillson
Dec 21 '18 at 8:20
1
1
Something so simple, but I couldn't get my head round it. Thank you for your help. 1st example does the job!
– dan
Dec 20 '18 at 11:58
Something so simple, but I couldn't get my head round it. Thank you for your help. 1st example does the job!
– dan
Dec 20 '18 at 11:58
1
1
@dan note that nested IFs can only get so many levels deep. This solution won't scale.
VLOOKUP would be much simpler, and would require zero maintenance, should the thresholds ever need to change.– Mathieu Guindon
Dec 20 '18 at 15:39
@dan note that nested IFs can only get so many levels deep. This solution won't scale.
VLOOKUP would be much simpler, and would require zero maintenance, should the thresholds ever need to change.– Mathieu Guindon
Dec 20 '18 at 15:39
1
1
"Something so simple" ? @dan I think u misunderstood it.. It is NOT simple.. || It's head-scratching even for a junior programmer when they started to learn recursively call a function. || In your case it is lucky coz the function involved is the basic IF(). If it is a recursive index()+match() , then I don't think it is easily explained. || Either way.. congratulation upon learning this new skill, and making an effort to make (the original) question simple and straightforwardly understandable. ( :
– p._phidot_
Dec 20 '18 at 17:16
"Something so simple" ? @dan I think u misunderstood it.. It is NOT simple.. || It's head-scratching even for a junior programmer when they started to learn recursively call a function. || In your case it is lucky coz the function involved is the basic IF(). If it is a recursive index()+match() , then I don't think it is easily explained. || Either way.. congratulation upon learning this new skill, and making an effort to make (the original) question simple and straightforwardly understandable. ( :
– p._phidot_
Dec 20 '18 at 17:16
The second example returned an error when I tried it. And you can have fewer nesting levels with a binary search:
=IF(Y8<20,IF(Y8<10,"Level 1", "Level 2"),IF(Y8<30,"Level 3","Level 4"))– Acccumulation
Dec 20 '18 at 18:36
The second example returned an error when I tried it. And you can have fewer nesting levels with a binary search:
=IF(Y8<20,IF(Y8<10,"Level 1", "Level 2"),IF(Y8<30,"Level 3","Level 4"))– Acccumulation
Dec 20 '18 at 18:36
cheers Accumulation - added a missing comma to the second code snippet.
– RickyTillson
Dec 21 '18 at 8:20
cheers Accumulation - added a missing comma to the second code snippet.
– RickyTillson
Dec 21 '18 at 8:20
add a comment |
You can use CHOOSE with MATCH
=CHOOSE(MATCH(Y8,{0,10,20,30}),"Level 1","Level 2","Level 3","Level 4")
If you are really wanting the Level and a number we can do:
="Level " & MATCH(Y8,{0,10,20,30})
This solution scales better than the nested IFs picked by the OP.
– Mathieu Guindon
Dec 20 '18 at 15:43
Nice ! wish I had thought of using MATCH in my answer...
– PeterH
Dec 20 '18 at 15:49
add a comment |
You can use CHOOSE with MATCH
=CHOOSE(MATCH(Y8,{0,10,20,30}),"Level 1","Level 2","Level 3","Level 4")
If you are really wanting the Level and a number we can do:
="Level " & MATCH(Y8,{0,10,20,30})
This solution scales better than the nested IFs picked by the OP.
– Mathieu Guindon
Dec 20 '18 at 15:43
Nice ! wish I had thought of using MATCH in my answer...
– PeterH
Dec 20 '18 at 15:49
add a comment |
You can use CHOOSE with MATCH
=CHOOSE(MATCH(Y8,{0,10,20,30}),"Level 1","Level 2","Level 3","Level 4")
If you are really wanting the Level and a number we can do:
="Level " & MATCH(Y8,{0,10,20,30})
You can use CHOOSE with MATCH
=CHOOSE(MATCH(Y8,{0,10,20,30}),"Level 1","Level 2","Level 3","Level 4")
If you are really wanting the Level and a number we can do:
="Level " & MATCH(Y8,{0,10,20,30})
edited Dec 20 '18 at 19:52
answered Dec 20 '18 at 14:41
Scott CranerScott Craner
11.3k1815
11.3k1815
This solution scales better than the nested IFs picked by the OP.
– Mathieu Guindon
Dec 20 '18 at 15:43
Nice ! wish I had thought of using MATCH in my answer...
– PeterH
Dec 20 '18 at 15:49
add a comment |
This solution scales better than the nested IFs picked by the OP.
– Mathieu Guindon
Dec 20 '18 at 15:43
Nice ! wish I had thought of using MATCH in my answer...
– PeterH
Dec 20 '18 at 15:49
This solution scales better than the nested IFs picked by the OP.
– Mathieu Guindon
Dec 20 '18 at 15:43
This solution scales better than the nested IFs picked by the OP.
– Mathieu Guindon
Dec 20 '18 at 15:43
Nice ! wish I had thought of using MATCH in my answer...
– PeterH
Dec 20 '18 at 15:49
Nice ! wish I had thought of using MATCH in my answer...
– PeterH
Dec 20 '18 at 15:49
add a comment |
Make a sorted lookup table with the Level corresponding to each threshold:
Value Level
0 1
10 2
20 3
30 4
Now you can use a simple VLOOKUP to get the Level given any Value, and if the thresholds ever need to change, or if new levels need to be added, your VLOOKUP formula doesn't need to change - just maintain the thresholds table, and done.
="Level " & VLOOKUP(theValue, theLookupTable, 2, TRUE)
Note the TRUE argument for the last parameter, making VLOOKUP use an approximate match rather than the typically-used exact match mode. As long as the thresholds are sorted ascending, VLOOKUP will return the Level value for the largest Value that is still smaller than the lookup value.

add a comment |
Make a sorted lookup table with the Level corresponding to each threshold:
Value Level
0 1
10 2
20 3
30 4
Now you can use a simple VLOOKUP to get the Level given any Value, and if the thresholds ever need to change, or if new levels need to be added, your VLOOKUP formula doesn't need to change - just maintain the thresholds table, and done.
="Level " & VLOOKUP(theValue, theLookupTable, 2, TRUE)
Note the TRUE argument for the last parameter, making VLOOKUP use an approximate match rather than the typically-used exact match mode. As long as the thresholds are sorted ascending, VLOOKUP will return the Level value for the largest Value that is still smaller than the lookup value.

add a comment |
Make a sorted lookup table with the Level corresponding to each threshold:
Value Level
0 1
10 2
20 3
30 4
Now you can use a simple VLOOKUP to get the Level given any Value, and if the thresholds ever need to change, or if new levels need to be added, your VLOOKUP formula doesn't need to change - just maintain the thresholds table, and done.
="Level " & VLOOKUP(theValue, theLookupTable, 2, TRUE)
Note the TRUE argument for the last parameter, making VLOOKUP use an approximate match rather than the typically-used exact match mode. As long as the thresholds are sorted ascending, VLOOKUP will return the Level value for the largest Value that is still smaller than the lookup value.

Make a sorted lookup table with the Level corresponding to each threshold:
Value Level
0 1
10 2
20 3
30 4
Now you can use a simple VLOOKUP to get the Level given any Value, and if the thresholds ever need to change, or if new levels need to be added, your VLOOKUP formula doesn't need to change - just maintain the thresholds table, and done.
="Level " & VLOOKUP(theValue, theLookupTable, 2, TRUE)
Note the TRUE argument for the last parameter, making VLOOKUP use an approximate match rather than the typically-used exact match mode. As long as the thresholds are sorted ascending, VLOOKUP will return the Level value for the largest Value that is still smaller than the lookup value.

answered Dec 20 '18 at 15:36
Mathieu GuindonMathieu Guindon
599211
599211
add a comment |
add a comment |
I like the answer by Scott Craner. However, I thought I would point out some other options.
If you have Excel 2016 or later, your can use the IFS function to simplify the structure of nested IF functions.
=IFS(Y8<10,"Level 1",Y8<20,"Level 2",Y8<30,"Level 3",TRUE,"Level 4")
The way it works is:
- If Y8 is less than 10, it will return "Level 1", otherwise ...
- If Y8 is less than 20, it will return "Level 2", otherwise ...
- If Y8 is less than 30, it will return "Level 3", otherwise ...
- It will return "Level 4"
In the example given in the question, the "level" number increases by one each time the value in Y8 increases by 10. In this special case, it is possible to calculate the level number without using IF.
="Level "&INT(MIN(30,MAX(0,Y8))/10)+1
Note that the question states that any value less than 10 is level 1 and any value greater than 30 is level 4. In order to force negative numbers to be "Level 1" and numbers greater than 39 to be level 4, the formula uses MIN(30,MAX(0,Y8)) instead of Y8.
my personal favorite answer.. nailed it.. nice shoot. || for @dan .. this is a mathematically induced dose on excel formula.. inputOutput pattern matching method.. best the best an algo can get. ( :
– p._phidot_
Dec 20 '18 at 17:22
@p._phidot_ Agree on the soundness of the math-based approach, but disagree that it's the best way to go: it makes an assumption on the data and encodes it into terse math logic. If the assumptions are ever invalidated (e.g. 6 months later, need a level 5 for 50+), then everything needs to be rewritten. Upvoted forIFS, but the math-based approach isn't respecting the original specifications for the upper bound value (i.e. return 4 for 30+), and making it so would involve further complicating the formula, making it encode even more metadata rather than simply reading like the specs.
– Mathieu Guindon
Dec 20 '18 at 18:02
@MathieuGuindon I thoroughly agree that the maths-based approach is not the best one for the general case, the OP would have to consider how set in stone the "10 values per level" pattern is. Thanks for pointing out that I didn't correctly handle the >30 case. I'll correct that (although, as you say, it will make the formula more complicated).
– Blackwood
Dec 20 '18 at 18:14
@MathieuGuindon Thanks for the heads up.. in general case, I'd agree with you. ( : || "the best" statement only goes for me I guess.. with my favorite theme of doing things... may not be the best for others.. || IMHO, if this was a competition, this solution will easily lose.. but , it worth an honorable mention.
– p._phidot_
Dec 21 '18 at 1:07
@p._phidot_ eh, I'm severely biased towards separating logic and data (programmer background, I guess); logic is usually dead-simple, it's the changing data/metadata that complicates things - IMO that's the case here; inlining the array (as in the top-voted answer) works for small sets, but won't scale nicely to e.g. 100 items ...which may or may not be a concern or even a possibility. Full separation of the data (as in mine) can be overkill, but seldom fails to scale and makes maintenance simpler, again just IMO =)
– Mathieu Guindon
Dec 21 '18 at 1:13
add a comment |
I like the answer by Scott Craner. However, I thought I would point out some other options.
If you have Excel 2016 or later, your can use the IFS function to simplify the structure of nested IF functions.
=IFS(Y8<10,"Level 1",Y8<20,"Level 2",Y8<30,"Level 3",TRUE,"Level 4")
The way it works is:
- If Y8 is less than 10, it will return "Level 1", otherwise ...
- If Y8 is less than 20, it will return "Level 2", otherwise ...
- If Y8 is less than 30, it will return "Level 3", otherwise ...
- It will return "Level 4"
In the example given in the question, the "level" number increases by one each time the value in Y8 increases by 10. In this special case, it is possible to calculate the level number without using IF.
="Level "&INT(MIN(30,MAX(0,Y8))/10)+1
Note that the question states that any value less than 10 is level 1 and any value greater than 30 is level 4. In order to force negative numbers to be "Level 1" and numbers greater than 39 to be level 4, the formula uses MIN(30,MAX(0,Y8)) instead of Y8.
my personal favorite answer.. nailed it.. nice shoot. || for @dan .. this is a mathematically induced dose on excel formula.. inputOutput pattern matching method.. best the best an algo can get. ( :
– p._phidot_
Dec 20 '18 at 17:22
@p._phidot_ Agree on the soundness of the math-based approach, but disagree that it's the best way to go: it makes an assumption on the data and encodes it into terse math logic. If the assumptions are ever invalidated (e.g. 6 months later, need a level 5 for 50+), then everything needs to be rewritten. Upvoted forIFS, but the math-based approach isn't respecting the original specifications for the upper bound value (i.e. return 4 for 30+), and making it so would involve further complicating the formula, making it encode even more metadata rather than simply reading like the specs.
– Mathieu Guindon
Dec 20 '18 at 18:02
@MathieuGuindon I thoroughly agree that the maths-based approach is not the best one for the general case, the OP would have to consider how set in stone the "10 values per level" pattern is. Thanks for pointing out that I didn't correctly handle the >30 case. I'll correct that (although, as you say, it will make the formula more complicated).
– Blackwood
Dec 20 '18 at 18:14
@MathieuGuindon Thanks for the heads up.. in general case, I'd agree with you. ( : || "the best" statement only goes for me I guess.. with my favorite theme of doing things... may not be the best for others.. || IMHO, if this was a competition, this solution will easily lose.. but , it worth an honorable mention.
– p._phidot_
Dec 21 '18 at 1:07
@p._phidot_ eh, I'm severely biased towards separating logic and data (programmer background, I guess); logic is usually dead-simple, it's the changing data/metadata that complicates things - IMO that's the case here; inlining the array (as in the top-voted answer) works for small sets, but won't scale nicely to e.g. 100 items ...which may or may not be a concern or even a possibility. Full separation of the data (as in mine) can be overkill, but seldom fails to scale and makes maintenance simpler, again just IMO =)
– Mathieu Guindon
Dec 21 '18 at 1:13
add a comment |
I like the answer by Scott Craner. However, I thought I would point out some other options.
If you have Excel 2016 or later, your can use the IFS function to simplify the structure of nested IF functions.
=IFS(Y8<10,"Level 1",Y8<20,"Level 2",Y8<30,"Level 3",TRUE,"Level 4")
The way it works is:
- If Y8 is less than 10, it will return "Level 1", otherwise ...
- If Y8 is less than 20, it will return "Level 2", otherwise ...
- If Y8 is less than 30, it will return "Level 3", otherwise ...
- It will return "Level 4"
In the example given in the question, the "level" number increases by one each time the value in Y8 increases by 10. In this special case, it is possible to calculate the level number without using IF.
="Level "&INT(MIN(30,MAX(0,Y8))/10)+1
Note that the question states that any value less than 10 is level 1 and any value greater than 30 is level 4. In order to force negative numbers to be "Level 1" and numbers greater than 39 to be level 4, the formula uses MIN(30,MAX(0,Y8)) instead of Y8.
I like the answer by Scott Craner. However, I thought I would point out some other options.
If you have Excel 2016 or later, your can use the IFS function to simplify the structure of nested IF functions.
=IFS(Y8<10,"Level 1",Y8<20,"Level 2",Y8<30,"Level 3",TRUE,"Level 4")
The way it works is:
- If Y8 is less than 10, it will return "Level 1", otherwise ...
- If Y8 is less than 20, it will return "Level 2", otherwise ...
- If Y8 is less than 30, it will return "Level 3", otherwise ...
- It will return "Level 4"
In the example given in the question, the "level" number increases by one each time the value in Y8 increases by 10. In this special case, it is possible to calculate the level number without using IF.
="Level "&INT(MIN(30,MAX(0,Y8))/10)+1
Note that the question states that any value less than 10 is level 1 and any value greater than 30 is level 4. In order to force negative numbers to be "Level 1" and numbers greater than 39 to be level 4, the formula uses MIN(30,MAX(0,Y8)) instead of Y8.
edited Dec 20 '18 at 18:18
answered Dec 20 '18 at 16:55
BlackwoodBlackwood
2,88861728
2,88861728
my personal favorite answer.. nailed it.. nice shoot. || for @dan .. this is a mathematically induced dose on excel formula.. inputOutput pattern matching method.. best the best an algo can get. ( :
– p._phidot_
Dec 20 '18 at 17:22
@p._phidot_ Agree on the soundness of the math-based approach, but disagree that it's the best way to go: it makes an assumption on the data and encodes it into terse math logic. If the assumptions are ever invalidated (e.g. 6 months later, need a level 5 for 50+), then everything needs to be rewritten. Upvoted forIFS, but the math-based approach isn't respecting the original specifications for the upper bound value (i.e. return 4 for 30+), and making it so would involve further complicating the formula, making it encode even more metadata rather than simply reading like the specs.
– Mathieu Guindon
Dec 20 '18 at 18:02
@MathieuGuindon I thoroughly agree that the maths-based approach is not the best one for the general case, the OP would have to consider how set in stone the "10 values per level" pattern is. Thanks for pointing out that I didn't correctly handle the >30 case. I'll correct that (although, as you say, it will make the formula more complicated).
– Blackwood
Dec 20 '18 at 18:14
@MathieuGuindon Thanks for the heads up.. in general case, I'd agree with you. ( : || "the best" statement only goes for me I guess.. with my favorite theme of doing things... may not be the best for others.. || IMHO, if this was a competition, this solution will easily lose.. but , it worth an honorable mention.
– p._phidot_
Dec 21 '18 at 1:07
@p._phidot_ eh, I'm severely biased towards separating logic and data (programmer background, I guess); logic is usually dead-simple, it's the changing data/metadata that complicates things - IMO that's the case here; inlining the array (as in the top-voted answer) works for small sets, but won't scale nicely to e.g. 100 items ...which may or may not be a concern or even a possibility. Full separation of the data (as in mine) can be overkill, but seldom fails to scale and makes maintenance simpler, again just IMO =)
– Mathieu Guindon
Dec 21 '18 at 1:13
add a comment |
my personal favorite answer.. nailed it.. nice shoot. || for @dan .. this is a mathematically induced dose on excel formula.. inputOutput pattern matching method.. best the best an algo can get. ( :
– p._phidot_
Dec 20 '18 at 17:22
@p._phidot_ Agree on the soundness of the math-based approach, but disagree that it's the best way to go: it makes an assumption on the data and encodes it into terse math logic. If the assumptions are ever invalidated (e.g. 6 months later, need a level 5 for 50+), then everything needs to be rewritten. Upvoted forIFS, but the math-based approach isn't respecting the original specifications for the upper bound value (i.e. return 4 for 30+), and making it so would involve further complicating the formula, making it encode even more metadata rather than simply reading like the specs.
– Mathieu Guindon
Dec 20 '18 at 18:02
@MathieuGuindon I thoroughly agree that the maths-based approach is not the best one for the general case, the OP would have to consider how set in stone the "10 values per level" pattern is. Thanks for pointing out that I didn't correctly handle the >30 case. I'll correct that (although, as you say, it will make the formula more complicated).
– Blackwood
Dec 20 '18 at 18:14
@MathieuGuindon Thanks for the heads up.. in general case, I'd agree with you. ( : || "the best" statement only goes for me I guess.. with my favorite theme of doing things... may not be the best for others.. || IMHO, if this was a competition, this solution will easily lose.. but , it worth an honorable mention.
– p._phidot_
Dec 21 '18 at 1:07
@p._phidot_ eh, I'm severely biased towards separating logic and data (programmer background, I guess); logic is usually dead-simple, it's the changing data/metadata that complicates things - IMO that's the case here; inlining the array (as in the top-voted answer) works for small sets, but won't scale nicely to e.g. 100 items ...which may or may not be a concern or even a possibility. Full separation of the data (as in mine) can be overkill, but seldom fails to scale and makes maintenance simpler, again just IMO =)
– Mathieu Guindon
Dec 21 '18 at 1:13
my personal favorite answer.. nailed it.. nice shoot. || for @dan .. this is a mathematically induced dose on excel formula.. inputOutput pattern matching method.. best the best an algo can get. ( :
– p._phidot_
Dec 20 '18 at 17:22
my personal favorite answer.. nailed it.. nice shoot. || for @dan .. this is a mathematically induced dose on excel formula.. inputOutput pattern matching method.. best the best an algo can get. ( :
– p._phidot_
Dec 20 '18 at 17:22
@p._phidot_ Agree on the soundness of the math-based approach, but disagree that it's the best way to go: it makes an assumption on the data and encodes it into terse math logic. If the assumptions are ever invalidated (e.g. 6 months later, need a level 5 for 50+), then everything needs to be rewritten. Upvoted for
IFS, but the math-based approach isn't respecting the original specifications for the upper bound value (i.e. return 4 for 30+), and making it so would involve further complicating the formula, making it encode even more metadata rather than simply reading like the specs.– Mathieu Guindon
Dec 20 '18 at 18:02
@p._phidot_ Agree on the soundness of the math-based approach, but disagree that it's the best way to go: it makes an assumption on the data and encodes it into terse math logic. If the assumptions are ever invalidated (e.g. 6 months later, need a level 5 for 50+), then everything needs to be rewritten. Upvoted for
IFS, but the math-based approach isn't respecting the original specifications for the upper bound value (i.e. return 4 for 30+), and making it so would involve further complicating the formula, making it encode even more metadata rather than simply reading like the specs.– Mathieu Guindon
Dec 20 '18 at 18:02
@MathieuGuindon I thoroughly agree that the maths-based approach is not the best one for the general case, the OP would have to consider how set in stone the "10 values per level" pattern is. Thanks for pointing out that I didn't correctly handle the >30 case. I'll correct that (although, as you say, it will make the formula more complicated).
– Blackwood
Dec 20 '18 at 18:14
@MathieuGuindon I thoroughly agree that the maths-based approach is not the best one for the general case, the OP would have to consider how set in stone the "10 values per level" pattern is. Thanks for pointing out that I didn't correctly handle the >30 case. I'll correct that (although, as you say, it will make the formula more complicated).
– Blackwood
Dec 20 '18 at 18:14
@MathieuGuindon Thanks for the heads up.. in general case, I'd agree with you. ( : || "the best" statement only goes for me I guess.. with my favorite theme of doing things... may not be the best for others.. || IMHO, if this was a competition, this solution will easily lose.. but , it worth an honorable mention.
– p._phidot_
Dec 21 '18 at 1:07
@MathieuGuindon Thanks for the heads up.. in general case, I'd agree with you. ( : || "the best" statement only goes for me I guess.. with my favorite theme of doing things... may not be the best for others.. || IMHO, if this was a competition, this solution will easily lose.. but , it worth an honorable mention.
– p._phidot_
Dec 21 '18 at 1:07
@p._phidot_ eh, I'm severely biased towards separating logic and data (programmer background, I guess); logic is usually dead-simple, it's the changing data/metadata that complicates things - IMO that's the case here; inlining the array (as in the top-voted answer) works for small sets, but won't scale nicely to e.g. 100 items ...which may or may not be a concern or even a possibility. Full separation of the data (as in mine) can be overkill, but seldom fails to scale and makes maintenance simpler, again just IMO =)
– Mathieu Guindon
Dec 21 '18 at 1:13
@p._phidot_ eh, I'm severely biased towards separating logic and data (programmer background, I guess); logic is usually dead-simple, it's the changing data/metadata that complicates things - IMO that's the case here; inlining the array (as in the top-voted answer) works for small sets, but won't scale nicely to e.g. 100 items ...which may or may not be a concern or even a possibility. Full separation of the data (as in mine) can be overkill, but seldom fails to scale and makes maintenance simpler, again just IMO =)
– Mathieu Guindon
Dec 21 '18 at 1:13
add a comment |
Another solution is to create a table holding the lower bounds of your values and using VLOOKUP
table with level values
=VLOOKUP(lookup value, table array, col_index_num,[range lookup])
The last variable in VLOOKUP is "Approximate match" TRUE/FALSE
Choosing the former will have the function attempt to find the "nearest value" with numbers this results in the function looking for any value "lower" than the input in the table. Using 9 as an example the closest result is 0 and will return "level 1".
this method also allows you to increase your options and levels on the fly.
That's... the answer I posted 15 minutes ago.
– Mathieu Guindon
Dec 20 '18 at 15:53
Yeah I was otherwise occupied while typing this. Will upvote yours though.
– Durielblood
Dec 20 '18 at 15:55
2
Yay team-vlookup!
– Mathieu Guindon
Dec 20 '18 at 16:00
2
Welcome to Super User. It isn't uncommon for someone to post a nearly identical solution while you're is working on their own. The intention is that each answer should provide a solution that hasn't already been contributed. In that situation, unless your answer adds something substantive, consider deleting it. It happens to everyone. :-)
– fixer1234
Dec 20 '18 at 16:12
add a comment |
Another solution is to create a table holding the lower bounds of your values and using VLOOKUP
table with level values
=VLOOKUP(lookup value, table array, col_index_num,[range lookup])
The last variable in VLOOKUP is "Approximate match" TRUE/FALSE
Choosing the former will have the function attempt to find the "nearest value" with numbers this results in the function looking for any value "lower" than the input in the table. Using 9 as an example the closest result is 0 and will return "level 1".
this method also allows you to increase your options and levels on the fly.
That's... the answer I posted 15 minutes ago.
– Mathieu Guindon
Dec 20 '18 at 15:53
Yeah I was otherwise occupied while typing this. Will upvote yours though.
– Durielblood
Dec 20 '18 at 15:55
2
Yay team-vlookup!
– Mathieu Guindon
Dec 20 '18 at 16:00
2
Welcome to Super User. It isn't uncommon for someone to post a nearly identical solution while you're is working on their own. The intention is that each answer should provide a solution that hasn't already been contributed. In that situation, unless your answer adds something substantive, consider deleting it. It happens to everyone. :-)
– fixer1234
Dec 20 '18 at 16:12
add a comment |
Another solution is to create a table holding the lower bounds of your values and using VLOOKUP
table with level values
=VLOOKUP(lookup value, table array, col_index_num,[range lookup])
The last variable in VLOOKUP is "Approximate match" TRUE/FALSE
Choosing the former will have the function attempt to find the "nearest value" with numbers this results in the function looking for any value "lower" than the input in the table. Using 9 as an example the closest result is 0 and will return "level 1".
this method also allows you to increase your options and levels on the fly.
Another solution is to create a table holding the lower bounds of your values and using VLOOKUP
table with level values
=VLOOKUP(lookup value, table array, col_index_num,[range lookup])
The last variable in VLOOKUP is "Approximate match" TRUE/FALSE
Choosing the former will have the function attempt to find the "nearest value" with numbers this results in the function looking for any value "lower" than the input in the table. Using 9 as an example the closest result is 0 and will return "level 1".
this method also allows you to increase your options and levels on the fly.
answered Dec 20 '18 at 15:52
E. KeijzerE. Keijzer
411
411
That's... the answer I posted 15 minutes ago.
– Mathieu Guindon
Dec 20 '18 at 15:53
Yeah I was otherwise occupied while typing this. Will upvote yours though.
– Durielblood
Dec 20 '18 at 15:55
2
Yay team-vlookup!
– Mathieu Guindon
Dec 20 '18 at 16:00
2
Welcome to Super User. It isn't uncommon for someone to post a nearly identical solution while you're is working on their own. The intention is that each answer should provide a solution that hasn't already been contributed. In that situation, unless your answer adds something substantive, consider deleting it. It happens to everyone. :-)
– fixer1234
Dec 20 '18 at 16:12
add a comment |
That's... the answer I posted 15 minutes ago.
– Mathieu Guindon
Dec 20 '18 at 15:53
Yeah I was otherwise occupied while typing this. Will upvote yours though.
– Durielblood
Dec 20 '18 at 15:55
2
Yay team-vlookup!
– Mathieu Guindon
Dec 20 '18 at 16:00
2
Welcome to Super User. It isn't uncommon for someone to post a nearly identical solution while you're is working on their own. The intention is that each answer should provide a solution that hasn't already been contributed. In that situation, unless your answer adds something substantive, consider deleting it. It happens to everyone. :-)
– fixer1234
Dec 20 '18 at 16:12
That's... the answer I posted 15 minutes ago.
– Mathieu Guindon
Dec 20 '18 at 15:53
That's... the answer I posted 15 minutes ago.
– Mathieu Guindon
Dec 20 '18 at 15:53
Yeah I was otherwise occupied while typing this. Will upvote yours though.
– Durielblood
Dec 20 '18 at 15:55
Yeah I was otherwise occupied while typing this. Will upvote yours though.
– Durielblood
Dec 20 '18 at 15:55
2
2
Yay team-vlookup!
– Mathieu Guindon
Dec 20 '18 at 16:00
Yay team-vlookup!
– Mathieu Guindon
Dec 20 '18 at 16:00
2
2
Welcome to Super User. It isn't uncommon for someone to post a nearly identical solution while you're is working on their own. The intention is that each answer should provide a solution that hasn't already been contributed. In that situation, unless your answer adds something substantive, consider deleting it. It happens to everyone. :-)
– fixer1234
Dec 20 '18 at 16:12
Welcome to Super User. It isn't uncommon for someone to post a nearly identical solution while you're is working on their own. The intention is that each answer should provide a solution that hasn't already been contributed. In that situation, unless your answer adds something substantive, consider deleting it. It happens to everyone. :-)
– fixer1234
Dec 20 '18 at 16:12
add a comment |
As an alternative to using nested IFs, you can use CHOOSE:
=IF(Y8>30,"Level 4",CHOOSE(MAX(1,ROUNDUP((Y8-1)/10,0)),"Level 1","Level 2","Level 3"))
Where there are only 4 different conditions I would usually use a series of nested IFs, but if you had say 100 conditions, it is a lot easier to use CHOOSE.
That doesn't work at all. Did you try any test values?
– Acccumulation
Dec 20 '18 at 18:42
Re try it, misplaced the bracket around the minus 1
– PeterH
Dec 21 '18 at 7:44
add a comment |
As an alternative to using nested IFs, you can use CHOOSE:
=IF(Y8>30,"Level 4",CHOOSE(MAX(1,ROUNDUP((Y8-1)/10,0)),"Level 1","Level 2","Level 3"))
Where there are only 4 different conditions I would usually use a series of nested IFs, but if you had say 100 conditions, it is a lot easier to use CHOOSE.
That doesn't work at all. Did you try any test values?
– Acccumulation
Dec 20 '18 at 18:42
Re try it, misplaced the bracket around the minus 1
– PeterH
Dec 21 '18 at 7:44
add a comment |
As an alternative to using nested IFs, you can use CHOOSE:
=IF(Y8>30,"Level 4",CHOOSE(MAX(1,ROUNDUP((Y8-1)/10,0)),"Level 1","Level 2","Level 3"))
Where there are only 4 different conditions I would usually use a series of nested IFs, but if you had say 100 conditions, it is a lot easier to use CHOOSE.
As an alternative to using nested IFs, you can use CHOOSE:
=IF(Y8>30,"Level 4",CHOOSE(MAX(1,ROUNDUP((Y8-1)/10,0)),"Level 1","Level 2","Level 3"))
Where there are only 4 different conditions I would usually use a series of nested IFs, but if you had say 100 conditions, it is a lot easier to use CHOOSE.
edited Dec 21 '18 at 7:43
answered Dec 20 '18 at 11:53
PeterHPeterH
3,49332347
3,49332347
That doesn't work at all. Did you try any test values?
– Acccumulation
Dec 20 '18 at 18:42
Re try it, misplaced the bracket around the minus 1
– PeterH
Dec 21 '18 at 7:44
add a comment |
That doesn't work at all. Did you try any test values?
– Acccumulation
Dec 20 '18 at 18:42
Re try it, misplaced the bracket around the minus 1
– PeterH
Dec 21 '18 at 7:44
That doesn't work at all. Did you try any test values?
– Acccumulation
Dec 20 '18 at 18:42
That doesn't work at all. Did you try any test values?
– Acccumulation
Dec 20 '18 at 18:42
Re try it, misplaced the bracket around the minus 1
– PeterH
Dec 21 '18 at 7:44
Re try it, misplaced the bracket around the minus 1
– PeterH
Dec 21 '18 at 7:44
add a comment |
Thanks for contributing an answer to Super User!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f1386242%2freturn-a-value-if-another-cell-has-one-of-many-values%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
2
I think "cases" is a better term than "argument".
– Acccumulation
Dec 20 '18 at 18:24