Question on Excel ifs statement using multiple matches - excel

Hopefully this is simple syntax. I want to write an Ifs statement that test if Cell 1 matches a cell in column A vs B vs C ect (these are all in different sheets). If it does the output if true is going to be A B or C in a third column that can be used as a region column.
However when I write this it only ever tests the first condition. I have written the formula in two ways and tested the entire column, instead of outputting if it was a CN or US customer it just gives me the first "result if true" and the rest are #N/A not even test for the second condition. Is this a simple syntax issue?
Note: this is a test condition ideally I this will sort between 5 regions not just two.
=IFS(MATCH('External by Region'!B1,'External by Region (us)'!B:B,0),"US",(MATCH('External by Region'!B1,'External by Region (cn)'!B:B,0)),"CN")
=IFS(MATCH('External by Region'!B1,'External by Region (cn)'!B:B,0),"CN", MATCH('External by Region'!B1,'External by Region (us)'!B:B,0),"US")

When MATCH does not find a match, it returns a NA error, which also causes IFS to error and terminate.
To make your formula work, handle the MATCH error by wrapping each MATCH() in NOT(ISERROR(...))
Eg
=IFS(NOT(ISERROR(MATCH('External by Region'!B1,'External by Region (us)'!B:B,0))),"US",
NOT(ISERROR(MATCH('External by Region'!B1,'External by Region (cn)'!B:B,0))),"CN")

Related

Error in Excel with Time function within Match function

I am trying to use the Match function to return the row of an indicated table that a certain time value is on. The time is in mm:ss format on the table, so I want users to input the desired time to match as text for their simplicity (with data validation to ensure its correct format), and then use the Time function within the Match function to convert the input to match the format of the table for comparison. However, when using the Time function, the Match function returns the incorrect row, one row number short of what it should be to be precise. I attempted to do some debugging (shown below) and looked into the documentation of both the Time and Match functions, but can't figure out why this would happen. Is there something about the Time function I'm missing?
Here is a breakdown of what I'm using and what I've done to debug and figure out it's the Time function that's causing me issues. Column R has the functions I've been using and their results, and Column S has direct links to the table to show what the output should be. Column T shows that the time values are exactly the same but that using them yields different results in the Match function. Column U is the user input time in text format, and columns V through X are just used to ensure we get to the correct column in the lookup table.
(https://i.stack.imgur.com/ageCW.png)
Here is a snip of the table being referenced in the Match function.
(https://i.stack.imgur.com/FgfGG.png)
Well, this is curious. This is NOT a proper answer, but I needed to enter this as an answer rather than a comment because I needed the space and the markup of a table. I created my own table and ran my own experiment.
I entered the time value of 00:01:23 three different ways:
I typed "00:01:23" into a cell manually.
I entered =TIME(0,1,23) in a cell
I typed "00:01:15" and "00:01:16" into two consecutive cells, and then dragged it down and let Excel autofill.
Here's the results I got:
How Entered
Value
Typed "00:01:23" in Excel
0.0009606481481481480000
=TIME(0,1,23)
0.0009606481481481480000
Fill
0.0009606481481481490000
I emphasized the digit that turned out unexpectedly different.
I then did a MATCH(x,x,1) down this column for each value and it resulted in exactly the behavior you observed. The first two matched 1:22, as they should, because they were ever so slightly less than the table value. The self-referencing MATCH() of the 1:23 cell correctly matched on 1:23.
What is puzzling to me is that my test revealed to me that the value in the lookup table was a tiny bit off, by (0.0000000000000000010000), where your test presented the exact same number, concealing the difference. So in my test, the MATCH() behaved correctly for the data given, even if the data was wrong.
Excel is limited to 15 significant digits, and I have no way of knowing what rounding shenanigans Excel goes through to drop the remaining digits.
My thought goes to wondering how the time values in your lookup table were first created to begin with. Like, were they initially entered in a google sheet and then opened in excel? Is the 15 significant digit rounding handled identically among excel versions and OSes?

Trying to find count of missed targets between 2 sheets

I am trying to work through this problem where I have 2 sheets (seen here as 2 sections for simplicity) and I am trying to count how many shipments from sheet 1 were below the SLA target in sheet 2.
The formula I tried was
IF(A21=INDEX(A2:A11,MATCH(A21,A2:A11,0),COUNTIF(C2:C11, ">="&C21))
I have tried multiple iterations of these parameters and have it returning some very inconsistent and totally wrong results. The output I am expecting is
0,0,1,3,0,0
I know this is going to probably be some kind of boolean algebra but I honestly do not understand how that system works. I have tried looking it up but I dont think i am doing it right.
Sample Data
You could use a simple boolean multiplier like this:
=SUM((A21=$A$2:$A$11)*($C$2:$C$11<C21))
This checks if the ID matches A21 and then multiplies these TRUE/FALSE results times a second boolean array that checks if the shipped amounts (C2:C11) are less than the SLA standard C21. NB: If it is really less than or equal, then use =SUM((A21=$A$2:$A$11)*($C$2:$C$11<=C21)). This generates a series of 1's for each value that matches the conditions and then SUM adds those one's up.
Using your example for ID Key 4/Item Name D, you would get:
SUM({FALSE,FALSE,FALSE,FALSE,FALSE,TRUE,TRUE,TRUE,FALSE,FALSE} * {TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE})
This gets coerced into:
SUM({0,0,0,0,0,1,1,1,0,0})

Multiple IF statements in Excel not working

I would like to set a multiple IF statement for my formula.
The reason behind it is, that I need to switch off the values (mark them as N/A and NA) which are equal to the other certain values as follows:
LP372/24/60+1=($NO372-720)/24/60+1 => mark them as N/A - the values, which don't happen during the midnight
and
LP372/24/60+1=$NO372/24/60+1 => mark them as NA - the values, that don't happen during the midday
The problem is, that I can't keep them under one IF statement, because I need the division.
So far I used only one IF statement (the nested one), which looks as follows:
=IF(OR((LP372/24/60+1)=(($NO372-720)/24/60+1), OR((LP372/24/60+1)=($NO372/24/60+1))),"N/A",LP372/24/60+1).
The value of NO372 corresponds to the rough time of the local midday. Substracting the 720 we are getting the rough midday for this location, knowing that the single day counts 24 hours x 60mins = 1440mins.
The formula above gives a nice result, but without the division between midday and midnight, which I am talking about.
Following my older query about the similar issue:
Double nested IF statement formula in Excel
I tried to solve it like this:
=IF(COUNTA(E1116:E1481),IF(OR((LP372/24/60+1)=(($NO372-720)/24/60+1),OR((LP372/24/60+1)=($NO372/24/60+1))),"N/A",LP372/24/60+1),"NA")
where the range E1116:E1481 corresponds to the whole year period (1.01 - 31.12).
Unfortunately I got nothing, similarity to this formula:
=IF(COUNTA(E1116:BC1116),IF(OR((LP372/24/60+1)=(($NO372-720)/24/60+1),OR((LP372/24/60+1)=($NO372/24/60+1))),"N/A",LQ510/24/60+1),"NA"),
where the E:1116:BC1116 range correspond to the all columns - circumstances as occur on January 1.
This formula was still not correct.
I found something on the web about the multiple IF statements:
which led me to the following formula
=IF((LP372/24/60+1)=(($NO372-720)/24/60+1);"N/A";IF((LP372/24/60+1)=($NO372/24/60+1);"NA")LP372/24/60+1)
Unfortunately again not correct.
The last attempt was an answer provided here:
Multiple IF statements in Excel
on which basis I built up another formula
=IF((LP372/24/60+1)=(($NO372-720)/24/60+1),"N/A",LP372/24/60+1,IF((LP372/24/60+1)=($NO372/24/60+1),"NA"))
this time Excel said, that I've entered too many arguments.
Is there a way to set up multiple IF statements?
I need to:
make the values equal to midnight as N/A,
make the values equal to midday as NA
keep the other values as they stand
This question was answered in the comments, but I thought I would add an answer with an example of how to nest IF statements for anyone that found this question because they are having issues with nesting IF statements.
When you add an IF statement to a formula in excel, you have to keep in mind that IF statements have 3 parts separated with commas:
The first value is the condition you are going to check
The second value is the value you want returned if that condition is true
The third value is the value you want returned if that condition is false
So here's an example that illustrates that:
=IF(condition to check, value if condition is true, value if condition is false)
Here is an example IF statement:
=IF(A1="Hello","World","something else")
If you are getting FALSE returned then your IF statement probably looks like this:
=IF(A1="Hello","World")
Notice that there are only 2 values inside this IF statement: the condition you are checking (A1="Hello") and what you want displayed if that is true ("World"). FALSE would be displayed if the value in A1 is something other than Hello because you haven't included the third value in the IF that defines what you want displayed if A1 is not Hello (this value is listed as something else in the example above)
It's best to try and avoid nesting IF statements if you can because they can be hard to keep track of. I would suggest using AND() or OR() instead if you can. They are very similar to each other, you list multiple conditions within the parens separated by commas that you will be checking against, and both evaluate to either True or False. The only difference is that for AND() every condition within the parens needs to be true for it to evaluate to True where OR() only one of the conditions listed in the parens needs to be true for it to return True.
So, for example, if you wanted to display World if A1 is Hello or Hi and you were to use nested IF statements it would look like this:
=IF(A1="Hello","World",IF(A1="Hi","World","something else"))
which in my opinion is really ugly. however, if you used OR() instead of nesting IF statements it would look like this:
=IF(OR(A1="Hello",A1="Hi"),"World","something else")
AND() works the same way, but instead of just needing one condition within the parens to be true to return True as OR() does, with AND() all conditions inside of the AND() need to be true to display your value instead of just one. here's an example AND():
=IF(AND(A1="Hello",B1=""),"World","something else")
in this case "World" would be displayed only if A1 is Hello AND B1 is empty
for both AND() and OR() you can have more than just 2 values inside if you need to check for more than 2 conditions, you just need to separate them each with commas, like this:
AND(condition1, condition2, condition3, ....)
OR(condition1, condition2, condition3, .....)
but, if you have to use nested IF statements, the easiest way I've found is to type IF( , , ) first thing to make sure you are allowing for all 3 values that need to be inside of the IF and you have the right amount of values inside the IF. If you are getting the message You've entered too many arguments for this function it is because you have entered more than 3 values inside your IF, like this:
=IF(A1="Hello","World","something else","this value is causing the issue")
so, to properly nest an IF in your formula, type IF( , , ) first off where you want the IF statement to be in your formula and then just fill in the blanks, then you avoid entering too few values which results in FALSE being displayed if your condition is not true or You've entered too many arguments for this function because you entered more than 3 values in your IF
Hope this helps to understand IF statements and how to nest them properly.

Excel, equation to output either 'Agent name', "COPY", or "Not Found"

I had an excel test that I didn't do particularly well on, but this one question had me stumped. I need an equation that takes the name in this list and outputs the agent name in 'first.initial' or "COPY" or "NOT FOUND"
Sheet 1:
Agent 
Adam.m
Agent 
David.e
Agent 
Joe.A 
Agent
Ben.B
Agent
Kat.C
Agent
Training.22
Agent
Admin
Convert these names: Correct output:
David Everit David.e
Joe a. Joe.A
Ben Ben.B
Sam p. NOT FOUND
Training 22 Training.22
David E. COPY
Kat Cathy Kat.C
David D. NOT FOUND
Adam.S NOT FOUND
The equation I submitted that my teacher said was wrong was:
=IFNA(IF(COUNTIF(Sheet1!A:A, A3)>1, "COPY", INDEX(Sheet1!A:A,MATCH(A3&"*",Sheet1!A:A,0))),"Not Found")
Well here's the thing.
You are checking the original data source for the name, pre-conversion. I must admit, the COPY was a bit misleading at first but I caught on later.
You are also wrapping the whole thing in a single logical... ISNA()... Your formula can only return TRUE, FALSE or an error from this.
Putting the wrapped ISNA() aside, this means that for your formula the majority of these entries are Not Found. True, if you instead had a list of data that had already been manipulated this would almost succeed. But you are checking for the "COPY" in the wrong data...
Your first task here would be to manipulate the data to the desired format of '[Firstname].[initial]' // So assuming that the first set of characters in the cell is always going to be the forename you can use a combination of something like:
=LEFT(A2,SEARCH(" ",A2)-1) - Gets the forname by returning the left-most characters to a length of the first space position minus 1.
=RIGHT(A2,LEN(A2)-SEARCH(" ",A2)) - Gets all characters to the right of space by determining the legth from the right as the total cell length minus the position of space.
You will need to perform a logical on the second scenario though as you want a single letter is it is a word or the entire thing if it is a number:
=IFERROR(RIGHT(A2,LEN(A2)-SEARCH(" ",A2))-0,MID(A2,SEARCH(" ",A2)+1,1))
So what i have done here is attempt to remove 0 from the string, if it is a number, this will succeed and return that number to us. If it fails it will produce an error and progress on to the second clause, giving us the single character.
You can combine these using simple string building or a concatenate clause:
=LEFT(A2,SEARCH(" ",A2)-1)&"."&IFERROR(RIGHT(A2,LEN(A2)-SEARCH(" ",A2))-0,MID(A2,SEARCH(" ",A2)+1,1))
or
=CONCATENATE(=LEFT(A2,SEARCH(" ",A2)-1),".",IFERROR(RIGHT(A2,LEN(A2)-SEARCH(" ",A2))-0,MID(A2,SEARCH(" ",A2)+1,1))
So now we are almost there, except that Ben and Adam are producing errors as there isn't a space character that can be found. We'll handle that error now so that we can move on to our search:
=IF(ISERROR(SEARCH(" ",A2)),A2,LEFT(A2,SEARCH(" ",A2)-1)&"."&IFERROR(RIGHT(A2,LEN(A2)-SEARCH(" ",A2))-0,MID(A2,SEARCH(" ",A2)+1,1))) - if you cannot find a space character then we will have the whole cell, otherwise, we will use the space to build the search term.
Now that we have the text formatted in the way that we want it, we can move forward to do the search, the order is important as we will need to first check our results from above for duplicates and print "COPY" where found, then look for the match and return it if it's there and lastly return "NOT FOUND" if we cannot find it.
We are going to need the use of the wildcard in order to satisfy the entry Ben. So let's show the logic first then throw the whole formula together:
=IF(COUNTIF($B$1:B1,[SearchTermFormula]),"COPY", - This part of the formula uses countif to check whether the search term already exists above it, returns "COPY" if so and will continue to the next part, the absolute referencing ($$) is important so that the range updates as you copy the formula down but keeps the first cell locked.
IF(ISNUMBER(MATCH([SearchTermFormula]&"*",Sheet1!$A$1:$A$14,0)),[SearchTermFormula],"NOT FOUND") - So this works to show the basic logical, again we use IF() to determine whether a match can be made as a number would be returned if so. We can then return the search term itself or "NOT FOUND".
A more elegent version of this part though would be:
IFERROR(INDEX(Sheet1!$A$1:$A$14,MATCH([SearchTermFormula]&"*",Sheet1!$A$1:$A$14,0)),"NOT FOUND"))
As it actually returns the result from sheet1 as well as making us use the [SearchTermFormula] 1 less time, using less resources.
INDEX() essentially maps the range as a 1 based array. What that means is the first cell in the range is considered an address of 1,1. You can think of it adding X and Y axis but 0,0 is outside the top left and the Y axis is inverted.
So we get it to index column A and MATCH returns the relative position, as the row's are equally sized, the relative position will be the row number we are after so we get the result returned or an error value, so IFERROR() leads us on to produce "NOT FOUND".
Putting all that together we have:
=IF(COUNTIF($B$1:B1,IF(ISERROR(SEARCH(" ",A2)),A2,LEFT(A2,SEARCH(" ",A2)-1)&"."&IFERROR(RIGHT(A2,LEN(A2)-SEARCH(" ",A2))-0,MID(A2,SEARCH(" ",A2)+1,1))))>0,"COPY",IFERROR(INDEX(Sheet1!$A$1:$A$14,MATCH(IF(ISERROR(SEARCH(" ",A2)),A2,LEFT(A2,SEARCH(" ",A2)-1)&"."&IFERROR(RIGHT(A2,LEN(A2)-SEARCH(" ",A2))-0,MID(A2,SEARCH(" ",A2)+1,1)))&"*",Sheet1!$A$1:$A$14,0)),"NOT FOUND"))
Sorry for the essay but I hope it helps you understand the scope

Nested IF function in excel not working

I am trying to implement an IF function for a simple pricing database where if a cell is equal to one of 3 time durations, the cell automatically generates the correct price based on length of time. Here's what I have so far based on what other examples have of nested Excel functions:
=IF(F4=12;"$60";IF(F4=6;"$40";IF(F4=3,"$30")))
My primary issue is that the second condition has a red bracket, indicating an error. If I then swap the ";" for a ",", I have the same result.
As there are only 3 conditions, I have also tried the following:
=IF(F4=12;"$60",IF(F4=6;"$40","$30")
But again I have the same issue with the bracket being red on the second condition.
Any ideas?

Resources