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).
Hi there so I have a list of items as follows - where in the Sample 1 column, Blue (I guess parent) is followed by Red (child) and the account numbers in Acct 1 should all be the same as the preceding Blue in that section (until the next Blue is listed with another acct number).
In the example below the 3th and 7th records need to be tagged/identified. Is there any easy way to do this with a formula? I have about 100K line items with this information. Thank you much!!
Sample 1 Acct
Blue 1234
Red 1234
Red 2458
Red 1234
Blue 5768
Red 5768
Red 2589
Red 5768
This is my suggestion. It looks before and after the current cell in column A to find the first cells which don't match in both directions, then takes the range between these cells. If there are at least as many cells in column B that don't match the current acct as do match it in the current range, then it is assumed that the current cell is a mistake (in the case where there are two children and their acct's don't match, then they would both be flagged).
=LET(range,INDEX(A:A,XMATCH(TRUE,A$1:A2<>A2,0,-1)+ROW(A$1)):INDEX(B:B,XMATCH(TRUE,A2:A$10<>A2,0)+ROW()-2),
sample,INDEX(range,0,1),
acct,INDEX(range,0,2),
equal,COUNTIF(acct,B2),
unequal,COUNTIF(acct,"<>"&B2),
unequal>=equal)
Unfortunately this formula doesn't work in conditional formatting, so it would mean putting it in a separate column, dragging it down and filtering on the TRUE values.
I will have a look at modifying the formula to work in CF.
This works in CF but is slow - will need to remove full-column ranges.
=LET(start,XMATCH(TRUE,A$1:A2<>A2,0,-1)+ROW(A$1),end,XMATCH(TRUE,A2:A$10<>A2,0)+ROW()-2,
sample,FILTER(A:A,(ROW(A:A)>=start)*(ROW(A:A)<=end)),
acct,FILTER(B:B,(ROW(B:B)>=start)*(ROW(B:B)<=end)),
equal,SUM(--(acct=B2)),
unequal,SUM(--(acct<>B2)),
unequal>=equal)
This I think is OK
=LET(start,XMATCH(TRUE,A$1:A2<>A2,0,-1)+1,end,XMATCH(TRUE,A2:A$10<>A2,0)+ROW()-ROW(A$1)-1,
seq,SEQUENCE(ROWS(A$1:A$10)),
sample,FILTER(A$1:A$10,(seq>=start)*(seq<=end)),
acct,FILTER(B$1:B$10,(seq>=start)*(seq<=end)),
equal,SUM(--(acct=B2)),
unequal,SUM(--(acct<>B2)),
unequal>=equal)
If I have misunderstood the whole thing and the parent and child is literally labelled as Blue or Red for the whole of sample 1, then you would just need this in conditional formatting:
=AND(A2="Red",B2<>XLOOKUP("Blue",A$1:A2,B$1:B2,,0,-1))
and this to mark each block with an increasing count
=IF(A2="Blue",C1+1,C1)
It's more efficient to do this with a spill formula that calculates the entire column at once.
I took a screenshot to explain the formula, but all that is required is one formula in cell C2.
Here is the unoptimised formula to create a spill column. It creates a bunch of arrays the height of your data and does operations on them to find the incorrect accounts.
=LET(
MultiLevelID, A2:A9,
Account, B2:B9,
sParent, "Blue",
sChild, "Red",
ArrayIndex, SEQUENCE(ROWS(MultiLevelID)),
ArrayBoolParent, ISNUMBER(XMATCH(MultiLevelID, sParent)),
ArrayParentIndex, IF(ArrayBoolParent=TRUE,ArrayIndex,0),
ArrayAllIndexes, XLOOKUP(ArrayIndex,ArrayParentIndex,ArrayParentIndex,,-1),
ArrayCorrectAccount, XLOOKUP(ArrayAllIndexes,ArrayIndex,Account),
ArrayBoolIncorrect, IF(Account=ArrayCorrectAccount,FALSE,TRUE),
ArrayBoolIncorrect
)
ArrayIndex is an array that starts at 1 and keeps counting up for the height of your data. SEQUENCE is for this exact purpose. It will be used as a 'row' reference. Note, these are rows relative to the selected data, not actual excel row numbers.
ArrayBoolParent is an array with TRUE for every parent and FALSE for every child. XMATCH is searching for the parent name, and returns the index if it is found and and error if not. ISNUMBER makes the output TRUE if found and FALSE if not. Using XMATCH lets you search for multiple criteria. For example, if "Light Blue" was also a parent, you could set sParent equal to `{"Blue", "Light Blue"}.
ArrayParentIndex is an array with the index for every parent and 0 for every child. I'm using an interesting application of IF to do this. When IF is given an array as the condition, it does an IF statement for each item in the array. When a return value is also an array, it returns the item relating to the condition instead of the whole array.
ArrayCorrectedIndexes is an array with all children's indexes pointing to their parent. Similar to IF, using an array with XLOOKUP performs the search on all items in the array separately. I'm also using one of the advanced functions of XLOOKUP, which says if a value isn't found, return the next largest value. This means when I search for index 2, it finds nothing and returns the next smallest value, 1.
ArrayCorrectAccount is an array with the parent account automatically assigned to each child. I used XLOOKUP for clarity, but you could also use INDEX(Account,ArrayCorrectedIndexes).
ArrayBoolIncorrect is an array that returns FALSE if the account is correct, and TRUE if not.
If you are looking for a summary of what needs to be fixed, only return the incorrect indexes:
FirstRow, MIN(ROW(MultiLevelID)) - 1,
FILTER(ArrayIndex + FirstRow, ArrayBoolIncorrect <> FALSE)
Lastly, if you want a dynamic table to summarize the errors, use this:
=LET(
MultiLevelID, A2:A9,
Account, B2:B9,
sParent, "Blue",
sChild, "Red",
FirstRow, MIN(ROW(MultiLevelID)) - 1,
ArrayIndex, SEQUENCE(ROWS(MultiLevelID)),
ArrayBoolParent, ISNUMBER(XMATCH(MultiLevelID, sParent)),
ArrayParentIndex, IF(ArrayBoolParent=TRUE,ArrayIndex,0),
ArrayCorrectedIndexes, XLOOKUP(ArrayIndex,ArrayParentIndex,ArrayParentIndex,,-1),
ArrayCorrectAccount, XLOOKUP(ArrayCorrectedIndexes,ArrayIndex,Account),
ArrayBoolIncorrect, IF(Account=ArrayCorrectAccount,FALSE,TRUE),
ArrayInccorrectIndexes, FILTER(ArrayIndex, ArrayBoolIncorrect <> FALSE),
ArrayInccorrectRows, ArrayInccorrectIndexes + FirstRow,
Categories, ArrayInccorrectIndexes,
Body_Instance, SEQUENCE(ROWS(Categories)),
Body_Parent, INDEX(MultiLevelID,INDEX(ArrayCorrectedIndexes, Categories)),
Body_Child, INDEX(MultiLevelID, Categories),
Body_IncorrectAcct, INDEX(Account, Categories),
Body_CorrectAcct, INDEX(ArrayCorrectAccount, Categories),
Body_IncorrectRows, ArrayInccorrectRows,
Total_Rows, COUNT(Categories),
Array_Seq, {1,2,3,4,5,6},
Array_Header, CHOOSE( Array_Seq, "Instance", "Row Location", "Parent", "Child", "Correct Acct", "Incorrect Acct", ),
Array_Body, CHOOSE( Array_Seq, Body_Instance, Body_IncorrectRows, Body_Parent, Body_Child, Body_CorrectAcct, Body_IncorrectAcct, ),
Array_Total, CHOOSE( Array_Seq, "", "", "", "", "Count", Total_Rows),
Range1,Array_Header,
Range2,Array_Body,
Range3,Array_Total,
Rows1,ROWS(Range1), Rows2,ROWS(Range2), Rows3,ROWS(Range3), Cols1,COLUMNS(Range1),
RowIndex, SEQUENCE(Rows1 + Rows2 + Rows3), ColIndex,SEQUENCE(1, Cols1),
RangeTable,IF(
RowIndex<=Rows1,
INDEX(Range1,RowIndex,ColIndex),
IF(RowIndex<=Rows1+Rows2,
INDEX(Range2,RowIndex-Rows1,ColIndex),
INDEX(Range3,RowIndex-Rows1-Rows2,ColIndex)
)),
Return, RangeTable,
Return
)
As you can see in my picture.
There is a table to the right.
Cell D3 has the option to select 90.0, 95.0, 99.0, and 99.9
Cell D4 is a % value
Cell D5 I have: IF(AND(D3=90,3/D4<9),3,4) Obviously if the user selects 90 for D3, then I want to determine which 2 X choices either 3 or 4 from the table are used based on the value of Y which I get by the 3/D4. This statement is working 100% correct.
MY QUESTION, How do I add the other parts of the table to this same line of code for when D3 = 95, 99, and 99.9?
I try this: =IF(OR(AND(D3=90, 3/D4<9),3,4, IF(AND(D3=95,4/D4<16),4,5)))
Try
=CHOOSE(MATCH(D3,{90,95,99,99.9},0),
IF(3/D4>= 9, 4,IF(3/D4>= 5,3,NA())),
IF(3/D4>=16, 5,IF(3/D4>= 7,4,NA())),
IF(3/D4>=20, 7,IF(3/D4>= 7,6,IF(3/D4>=6,5,NA()))),
IF(3/D4>=32,10,IF(3/D4>=15,9,IF(3/D4>=9,8,IF(3/D4>=8,7,NA()))))
)
In this formula MATCH(D3,{90,95,99,99.9},0) will return 1, 2, 3, or 4. This is used by CHOOSE to select the login in one of the four lines below.
Each of the next four lines is a nested IF statements. The question as asked has integer thresholds for 3/D4 and is a little ambiguous about things that fall in the gaps: for example, how do you handle C=90 and 3/D4=8.5. I've made the decision/assumption that when 3/D4<9, return 3. If that's wrong (for instance you want to round 3/D4 to an integer) you can modify the formula accordingly.
I've also made the decision to return NA when 3/D4 is below the lowest threshold. You can modify the formula to change that behavior too.
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.
I have an excel document with about 12,000 lines of part numbers with pricing information. I think the most intuitive way to sort them would be as follows:
1, 12, 15, 100, 10003, 2, 2002, 20005000, 3, 30, 333, 4, 5, 6, 700000, 800000.
All the numbers that begin with 1 are in the same spot, same with all 2 prefixes, etc. My problem is, excel's default sorting method sorts it like THIS:
1, 20, 30, 40, 100, 150, 200, 250, 500, 1000, 1500, 2000, 10000.
So it sorts them in regular ascending order, which I think makes it more difficult to find your part number, especially as they get super long as some of them do.
I don't have a lot of resources outside of excel at my workspace, so I would like to stick to using that. My knowledge of excel also isn't too impressive, so please treat me like an idiot!
To make thing easier to describe, let's assume that your list of part numbers is in column A, and that you have a blank column B.
In cell B2 enter this formula:
=TEXT(A1,"#")
Copy that down as far as your list goes.
Now, selecting both columns, Custom Sort by column B.
That's it.
Create a new column called SortOrder with the following formula:
=VALUE(LEFT(A2,1))
Then go to Home tab > Sort & Filter > Custom Sort.... Sort first by SortOrder, then by Value:
With data in column A like:
In B1 enter:
=CHAR(1) & A1
and copy down. Then sort cols A & B by B to get:
Is this "alphabetic-style" sort closer to what you need??