Nested IF function in excel not working - excel

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?

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?

Counting excel cells within a time window

I am trying to get a formula that will help count cells that fall within a time window. I came up with a formula but it only works when the time is from AM to PM and not for PM (previous day) to AM (next day). As shown in the image, I want to be able to count the number of Korea trades (from Table 2) within trading window (Table 3). I was trying to use the highlighted formula but apparently it's not working on Table 1.
Formula: =COUNTIFS(D13:D16, "Korea", E13:E16, ">="&H4, E13:E16, "<="&I4)
Is there a way to achieve this?
When the times cross midnight for Korea, you'll need to do an OR condition rather than an and condition. You could do this by making two countifs functions or use Sumproduct as shown below:
=SUMPRODUCT((D13:D16="Korea")*((E13:E16>=H3)+(E13:E16<=I3)))
If you have access to a version of Excel that supports the Lambda function I’d suggest creating a lambda that does the within checking so it’s not done through the formulas on your sheet. Unfortunately I don’t think there are Ifs functions that take a lamdba as a criteria but you might be able to use Map to generate an array of booleans and get the product similar to the other reply.
So I started by creating a lambda for determining if the value is in the range. The formula I used is:
=LAMBDA(s,e,IF(s<e,LAMBDA(x,AND(x>=s,x<e)),LAMBDA(x,OR(x<e,x>s))))
That basically takes 2 parameters - your starting time and the ending time for the range. It will return a lambda that will take the time to compare. And I added that as a namedreference named “IsWithin”
Then I created another lambda that would do the overall count.
=LAMBDA(rangeMatch,textMatch,rangeTime,start,end,SUM(MAP(rangeMatch,LAMBDA(x,ISNUMBER(SEARCH(textMatch,x))))*MAP(rangeTime,IsWithin(start,end))))
The function takes 5 parameters:
the range for which you are searching for the country name
the text to match within the range
the range containing the times to evaluate
the start time for the valid range (e.g. H3)
the end time for the valid range (e.g. I3)
It uses the Map function to evaluate the items in the range using lambdas. The first part of the evaluate creates an array of the items that have the matching text so either TRUE or FALSE. The second part creates an array of items that are within the specified time range - again either TRUE or FALSE. And then it just multiplies those arrays and sums the values essentially getting those where both values are true. Then to use it you just call that named reference:
=CountMatch(D13:D16,"Korea",E13:E16,H4,I4)
You can try this
=SUMPRODUCT(--(LEN(D13:D16)<>LEN(SUBSTITUTE(D13:D16,"Korea","")))*((E13:E16>=H4)+(E13:E16<=I4)))

Excel percentage increase based on formula

I am trying to fill the sell price column in an Excel spreadsheet with the increased values in colors based on the round up columns value (1 to 50 green, 50 to 100 blue, 100 to 150 yellow, 150+ pink).
I've opted for the percentage table because some items can be sold for a lot more than what I have purchased them for, so that's just for my benefit. I am open to any other suggestions and I am new to this whole business thing.
I was using IF in my formula which would work great for using one percentage increase in the formula:
=IF($E27<50,ROUNDUP(I$27,-1))
If I try to enter a second argument like
=IF(OR($E28<50,ROUNDUP(I$28,-1)OR($E28>50,<100,ROUNDUP(J$28,-1))))
I will get an error.
I'm probably using the formulas wrong, I've tried "AND" and a couple other formulas, but I can't find anyone else trying to achieve the same or similar.
So something like this:
=IF($E28<50,ROUNDUP(I$28,-1),IF($E28>50,ROUNDUP(J$28,-1),"Error"))
But not sure what the <100 was for.
Although the problem is not completely clear, I understand that you want to add a formula with nested if statements.
I will recommend you to try nested ifs in parts.
=IF($E27<50,ROUNDUP(I$27,-1),"First if condition is false")
If everything is working as per the requirement then edit that text in the formula to add another if statement.
=IF($E27<50,ROUNDUP(I$27,-1),IF(OR(condition 1, condition 2,more conditions),"value if true","value if false"))
In the second argument provided by you, the arguments of the OR function has not been properly provided. Ensure that all the arguments of an OR function are conditions separated by a comma.
$E28<50 This is a condition so it's ok.
But other arguments are not making sense.
Also, using OR multiple times inside the first OR arguments is not clear.
It would be beneficial if you could provide the basic table and mention the requirement clearly.

Question on Excel ifs statement using multiple matches

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")

Excel count instances of a value error

I need to count the amount of times a value shows up in the B column and display it in 3 seperate fields. What I came up with was this piece of code:
=COUNTIF(B2:B6716,"0")
=COUNTIF(B2:B6716,"1")
=COUNTIF(B2:B6716,"2")
But no matter how I enter this It keeps telling me the formula is incorrect. I tried removing the " around the three numbers aswell btw and even in order to test it I even used some words but it just won't work. Any idea how I can get this to work?
The error:
Try something like:
=COUNTIF(B1:B416; "=0")
As a criteria, you should rather put some string that appended to tested value forms a condition, not a particular number. This way, you can formulate more fancy criteria, like:
=COUNTIF(B1:B416; ">100")

Resources