create binding text and data in excel - excel

I'm trying to link these three words to their alternative number in excel,
not started, in progress, and done to 0, 0.5, and 1 respectively.
I tried to create a list of states and used them in column A, the same as the following image.
then I wrote a simple code in column B respectivly to achieve my desire like this:
=LOOKUP(A1,{"not started","in Progress","done"},{0,0.5,1})
(A1 changed to A2 and A3, respectively)
But the result was weird, and I do not have any idea what is my misunderstanding about the function lookup.
here is the result:
any help would be appreciated.

See LOOKUP Vector form:
The values in lookup_vector must be placed in ascending order: ..., -2, -1, 0, 1, 2, ..., A-Z, FALSE, TRUE; otherwise, LOOKUP might not return the correct value.
So, it should be: LOOKUP(A1,{"done","in progress","not started"},{1,0.5,0}) with 'd', 'i', 'n'.
If you don't want to bother with figuring out the correct order, you could use INDEX/MATCH:
=INDEX({0,0.5,1},MATCH(A1,{"not started","in progress","done"},0))

Why not IFS.
=IFS(A1="not started",0,A1="in progress",0.5,A1="done",1)

To expand on #ouroboros1 's answer, you might profit from the newer
dynamic array features by replacing the single cell reference by a range like e.g. A1:A100
=LOOKUP(A1:A100,{"done","in progress","not started"},{1,0.5,0})
and
=INDEX({0,0.5,1},MATCH(A1:A100,{"not started","in progress","done"},0))
Furthermore you can even omit the Index function in the latter formula by returning
the ordinal numeric findings within the given search array minus 1 and divided by 2:
=(MATCH(A1:A100,{"not started","in progress","done"},0)-1)/2
Note
If you don't dispose of versions 2019+|MS365 enter array formulae
via CtrlShiftEnter.
Further hints:
All examples (including nicholasfor's IFS solution) are case insensitive,
LookUp and IFS allow wild cards, too
LookUp needs an
ascending sort order as indicated (..., -2, -1, 0, 1, 2, ..., A-Z, FALSE, TRUE).

Related

How do I find the last number in a string with excel formulas

I'm parsing strings in excel, and I need to return everything through the last number. For example:
Input: A00XX
Output: A00
In my case, I know the last number will be between index 3 and 5, so I'm brute-forcing it with:
=LEFT([#Point],
IF(SUM((MID([#Point],5,1)={"0","1","2","3","4","5","6","7","8","9"})+0),5,
IF(SUM((MID([#Point],4,1)={"0","1","2","3","4","5","6","7","8","9"})+0),4,
IF(SUM((MID([#Point],3,1)={"0","1","2","3","4","5","6","7","8","9"})+0),3,
))))
Unfortunately, I've run into some edge cases where the numbers extended beyond index 5. Is there a generic way to find the last number in a string using excel formulas?
Note:
I've tried =MAX(SEARCH(... but it returns the index of the first number, not the last.
As a starting point: if we know the position of the last number, we can use LEFT to get the string to that point. Suppose that the position is 5:
=LEFT(A1, 5)
But, we don't know the position of the last number. Now, what if the only valid number was 0, and it only appeared once: then we could use FIND to locate the position of the number:
=LEFT(A1, FIND(0, A1))
But, we have more than one valid number. Suppose that we had all the numbers from 0 through 9, but each number could only appear once — then we could use MAX on a FIND array, to tell us which of the numbers is the last one:
=LEFT(A1, MAX(FIND({0,1,2,3,4,5,6,7,8,9}, A1)))
Unfortunately, FIND will throw a #VALUE! error any number doesn't appear, which will then make MAX return the same error. So, we need to fix that with IFERROR:
=LEFT(A1, MAX(IFERROR(FIND({0,1,2,3,4,5,6,7,8,9}, A1), 0)))
However, numbers can appear more than once. As such, we need a method to find the last occurrence of a value in a string (since FIND and SEARCH will, by default, return the first occurrence).
The SUBSTITUTE function has 3 mandatory arguments — Initial String, Value to be Replaced, Value to Replace with — and one Optional argument — the occurrence to replace. Normally, this is omitted, so that all occurrences are replaced. But, if we know how many times a character appears in a string, then we can replace just the last instance with a special/uncommon sub-string to search for.
To count how many times a character appears in a String, just start with the length of the String, then subtract the length when you SUBSTITUTE all copies of that character for Nothing:
=LEN(A1) - LEN(SUBSTITUTE(A1, 0, ""))
This means we can now replace the last occurrence of the character with, for example, ">¦<", and then FIND that:
=FIND(">¦<", SUBSTITUTE(A1, 0, ">¦<", LEN(A1) - LEN(SUBSTITUTE(A1, 0, ""))))
Of course, we want to do this for all the numbers from 0 to 9, and take the MAX value (remembering our IFERROR), so we need to put the Array of values back in:
=MAX(IFERROR(FIND(">¦<", SUBSTITUTE(A1, {0,1,2,3,4,5,6,7,8,9}, ">¦<", LEN(A1) - LEN(SUBSTITUTE(A1, {0,1,2,3,4,5,6,7,8,9}, "")))), 0))
Then, we plug that all back into our initial LEFT function:
=LEFT(A1, MAX(IFERROR(FIND(">¦<", SUBSTITUTE(A1, {0,1,2,3,4,5,6,7,8,9}, ">¦<", LEN(A1) - LEN(SUBSTITUTE(A1, {0,1,2,3,4,5,6,7,8,9}, "")))), 0)))
An alternative, assuming that the length of the string in question will never be more than 9 characters (which seems a safe assumption based on your description):
=LEFT(A1,MATCH(0,0+ISERR(0+MID(A1,{1;2;3;4;5;6;7;8;9},1))))
This, depending on your version of Excel, may or may not require committing with CTRL+SHIFT+ENTER.
Note also that the separator within the array constant {1;2;3;4;5;6;7;8;9} is the semicolon, which, for English-language versions of Excel, represents the row-separator. This may require amending if you are using a non-English-language version.
Of course, we can replace this static constant with a dynamic construction. However, since we are already making the assumption that 9 is an upper limit on the number of characters for the string in question, this would not seem to be necessary.
If you have the newest version of Excel, you can try something like:
=LEFT(D1,
LET(x, SEQUENCE(LEN(D1)),
MAX(IF(ISNUMBER(NUMBERVALUE(MID(D1, SEQUENCE(LEN(D1)), 1))), x))))
For example:

Is there an EXCEL formula that counts how many times Excel data 'switches' between binomial coding (i.e., data coded as 1 or 2)?

Folks, would really appreciate some help;
If I have the following values of data in Excel (3 examples below) where data is coded as 1 or 2, does anyone know an Excel formula which can count how many 'switches' occur in the sequence of values? What I mean by a 'switch', is when the 1's switch to 2's, and vice versa (when the 2's switch to 1's).
For example;
1, 1, 1, 1, 1, 1, 1, 2, 2 (there is 1 switch here)
1, 2, 2, 1, 1, 1, 1, 1, 1 (there are two switches here)
1, 2, 2, 1, 1, 1, 1, 2, 2 (there are three switches here)
So far, I am able to use the following formula (see below) to see IF there is a switch at all in the sequence (from 2 to 1 for example). But now I am trying to calculate how many switches are occurring in the sequence, and not IF a singular switch is occurring. So I think I possibly need to use a COUNT formula, instead of a FIND formula?
=IF(ISERROR(FIND("21",TEXTJOIN("",TRUE,[data range of a row]))),FALSE,TRUE)
Any help is appreciated.
If you have your data in cells A1 to I1, then use this formula:
=SUM(ABS(B1:I1-A1:H1))
I've tested this with your three inputs and it produces the expected answers.
If you would have access to FILTERXML (I believe from Excel 2013 onwards) you could use:
Formula in B1:
=COUNT(FILTERXML("<t><s>"&SUBSTITUTE(A1,", ","</s><s>")&"</s></t>","//s[following::*[1]!=.]"))
For your understanding; the xpath expression //s[following::*[1]!=.] will return all (child)nodes where the first following node is different then the current one. Then COUNT will actually count these returned numbers. Note that this will return 0 when no change occurs in your string.

Conditional IF() statement problem, not returning desired value

Currently writing a program in excel that will return a value based on user input. The current formula has 5 different return options which are returned based on the selection of a number by the user. I use the IF() statement embedded into more IF() statements to account for multiple input options. However, when I go to enter in a number beyond the range of the first IF() statement, I am getting 0 even though it should be a different number.
For the code below, C30 is the input cell and it should return .15 if I was to enter 25.
=IF(C30<20, 0.35, IF(20<C30<40, 0.15, IF(40<C30<60, 0, IF(60<C30<80, -0.1, IF(80<C30, -0.2, 0)))))
From the logic statements, it should be returning .15, but all I am getting is 0.
Excel does not use 20<C30<40 it would be:
AND(20<C30,C30<40)
But you can shorten this with a simple MATCH and CHOOSE:
=CHOOSE(MATCH(C30,{0,20,40,60,80}),0.35,0.15,0,-0.1,-0.2)
If you really want a nested if there is no need for the extra tests:
=IF(C30<20,0.35,IF(C30<40,0.15,IF(C30<60,0,IF(C30<80,-0.1,-0.2))))
IF will resolve sequentially and short circuit as soon as it finds the first TRUE, so it does not need the other logic.
The problem here is the logic that you have used to evaluate whether C30 falls within a range of numbers.
IF(20<C30<40,...) will not check whether C30 is in the range of 20 through 40.
Instead, use AND(cond1, cond2, ...) to check whether the values are within the range:
IF(AND(C30 > 20, C30 < 40), ...)
Replace terms like:
20<C30<40
with:
AND(20<C30,C30<40)
etc.

Excel Multiple Criteria Function with Between

So I have a cell with the following information, for example "Score 8/10" and I need a formula that translates to "if the value is between 0 and 4, return "Bad", if the value is between 5 and 7, return "Medium", if the value is between 8 and 10, return "Good".
I tried a If with a mid to extract the "8" from the "Score 8/10", but couldn't manage to get the rest of the result.
Please try:
=CHOOSE(MATCH(1*TRIM(MID(A1,FIND("/",A1)-2,2)),{0,5,8}),"Bad","Medium","Good")
Here is my answer, although I think #pnut's is preferable.
=IF(MID(A3,(FIND(" ",A3,1)+1),FIND("/",A3,(FIND(" ",A3,1)+1))-(FIND(" ",A3,1)+1))+0<5,"Bad", IF(MID(A3,(FIND(" ",A3,1)+1),FIND("/",A3,(FIND(" ",A3,1)+1))-(FIND(" ",A3,1)+1))+0>7, "Good","Medium"))
This gets the characters between the first space character and the first "/" character, converts them to a number and then compares than number to select an appropriate value.

Autopopulate another cell with a specific value from a drop down Liat

I select an input on cell L10 using a drop down list.
The values of the list are AH11, AH12, AH13, AH14, AH15 and AH16
Base on this selection, I want to auto populate the value in another cell.
I used the following formula in my target cell
=IF(OR(L10="AH11",L10="AH12"),"6",IF(OR(L10="AH15",L10="AH16"),"18"))
This works because AH11 and AH12 have the same values. Similarly for AH15 and 16.
But AH13 and AH 14 have their unique values.
How do I improve the formula to display values for AH13 and AH14 also?
Just nest the IF's further:
=IF(OR(L10="AH11",L10="AH12"),"6",IF(OR(L10="AH15",L10="AH16"),"18", IF(L10="AH13", "xx", IF(L10="AH14","yy"))))
Build an INDEX/MATCH using array constants instead of cell ranges.
=index({6, 6, 99, 100, 18, 18}, match(L10, {"AH11", "AH12", "AH13", "AH14", "AH15", "AH16"} , 0))
'with these progressive lookup values it can be shortened to,
=index({6, 99, 100, 18}, match(L10, {"AH11", "AH13", "AH14", "AH15"}))
I don't recommend that you return quoted text-that-looks-like-numbers. While there are limited special cases where this is desirable, it is almost always better to leave numbers as true numbers.

Resources