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?
Related
Working in Excel 2019. In the same realm as one of my previous questions, I'm working with a database that I'm trying to look through via functions to get my values. The VLOOKUP tool worked well for going through the time-table to find the value I need, but it's not working when I'm trying to find RPM as the look-up value. Here's the gist of the data.
We have Time(sec, A:A in "PPT_156Data" sheet), RPM (B:B in same sheet), and Pressure (Bar, C:C in same sheet).
From the graph, you can see that we ramp to 8000RPM over the course of around 60 seconds, and then ramp down to 0RPM over the next 30. Test times WILL vary and rates WILL vary from pump-to-pump, as each one will give different data values based on the pump. That's why, say, 1000RPM will not be in the same spot every time.
I'm trying to find the RPM at 1000 intervals up to 8000 and report out the pressure at said intervals.
Here's what I tried so far, with imagery as well.
'Disregard if you see W25 for S25, I had just been trying multiple things
First, I attempted the same VLOOKUP code I had done for the time-table prior
=VLOOKUP(S25,PPT156_Data!B:C,2,TRUE) 'S25 being lookup value
This worked fine, UP UNTIL it hit a particular spot. For some reason, as soon as it tries to find an approximate match for 6663RPM, it faults out and gives incorrect data. From then on, all the way to 8000RPM, it will ONLY give the result of 0.139BAR. I have no clue why. Trying to find that value in the return array gives multiple results, but it's not like it's the ONLY value left.
So, I tried to do a wildcard for it with the following code
=VLOOKUP("*"&S25&"*",PPT156_Data!B:C,2,FALSE) 'Attempted both False and True states
Gave N/A for both of the values. Not sure if I'm entering in the wildcard incorrectly here. The decimal places that the RPM can go to ranges between 2-5 (hundredths to hundred-thousandths, IE 7000.00750)
I then thought maybe an Index Match would work.
=INDEX(PPT156_Data!B:C,MATCH(S25,PPT156_Data!B:B,-1),2)
Tried that in wildcard format too, returned nothing. So, I decided to see if I could even match a value for RPM with the following attempts
=MATCH(S25,PPT_Data156!B:B,-1)
This gave nothing. HOWEVER, when setting the match specification to 1, it gives the very last row in the data set. So, I decided to find a value in column B, and attempt to match with it exactly.
=MATCH(7000.07,PPT_Data156!B:B,0)
This also returned nothing. Even though, you can see in my images, that the value is ABSOLUTELY there. SIGFIG shows it's 7000.1 but trust me, it's 7000.07. So that sort of threw me for a loop. Figuring maybe there was a different error and grasping at straws, tried another Index Match formula, this time subtracting the lookup value in an attempt to get it extremely close and absolute value/min it
=INDEX(PPT156_Data!C:C,MATCH(MIN(ABS(PPT156_Data!B:B-S25)),ABS(PPT156_Data!B:B-S25),1))
I'm at a loss. I'm not sure if because the rate ramps up and down, thus not being in ascending order, is causing a problem? I can't change that. I am thinking I may need to create a macro for this in some way? Maybe a helper table? But I can't even FIND the match value to create a helper table. Any help at all would be VERY appreciative.
Thank you for your time looking at my post.
I am presuming that you want the first pressure reading when the RPM hits above each 1000 interval. I got to a solution but feels a bit complex.
=index(C:C,1/max(iferror(1/(row(B:B)*(B:B>E12)),Null)))
Breaking this down, we create a boolean array where the RPM hits above the interval
=B:B>E12
and then we multiple this by the array of the rows of column B
row(B:B)*(B:B>E12)
which gives us an array of the row numbers when the RPM is above E12 but also zero for all the ones that do not.
=iferror(1/(row(B:B)*(B:B>E12)),Null)
We then force an error with the zeros by dividing and replace with null. We get the max since we inverse the row numbers and then inverse again to get the row number back.
=index(C:C,1/max(iferror(1/(row(B:B)*(B:B>E12)),Null)))
[Excel working screenshot][1]
[1]: https://i.stack.imgur.com/uhcaX.png
I'm trying to make my monthly transaction spreadsheet less work-intensive but I'm running up against problems outputting my category lookups as an array. Right now I have a table with all my monthly transactions and I want to create another table with monthly running totals. What I've been doing is manually summing each entry from each category, but I'd love to automate the process. Here's what I have:
=SUM(INDEX(Transactions[Out], N(IF(1,MATCH(I12,Transactions[Category],FALSE)))))
I've also tried using AGGREGATE in place of SUM but it still only returns the first value in the category. The N(IF()) was supposed to force INDEX to return all the matches as an array, but it's not working. I found that trick online, with no explanation of why it works, so I really don't know how to fix it. Any ideas?
Just in case anyone ever looks at this thread in the future, I was able to find a simpler solution to my problem once I implemented the Transactions[Category]=I12 method. SUM, itself will take an array as an argument, so all I had to do was form an array of the values I wanted to keep from Transactions[Out] range. I did this by adjusting the method Ron described above, but instead of using 1/(Transactions[Category]=I12 I used 1/IF(Transactions[Category]=I12, 1,1000) and surrounded that by a FLOOR(*resulting array*, .01) which rounded all the thousandth's down to zero and didn't yield any #DIV/0! errors.
Then! I realized that the simplest way to get the actual numbers I wanted, rather than messing with INDEX or AGGREGATE, was to multiply the range Transactions[Out] by the binary array from the IF test. Since the range is a table, I know they will always be the same size. And SUM automatically multiplies element by element and then adds for operations like this.
(The result is a "CSE" formula, which I guess isn't everyone's favorite. I'm still not 100% clear on what it means: just that it outputs data in a single cell, rather than over multiple cells. But in this context, SUM should only output a single number, so I'm not sure why I need CSE... A problem for another day!)
In your IF, the value_if_true clause needs to return an array of the desired row numbers from the array.
MATCH does not return an array of values; it only returns a single value which, with the FALSE parameter, will be the first value. That's why INDEX is only returning the first value.
One way to return an array of values:
Transactions[Category]=I12
will return an array of {TRUE,FALSE,FALSE,TRUE,...} depending on if it matches.
You can then multiply that by the Row number to get the relevant row on the worksheet.
Since you are using a table, to obtain the row number in the data body array, you have to subtract the row number of the Header row.
But now we are going to have an array which includes 0's for the non-matching entries, which is not good for us as a row number argument for the INDEX function.
So we get rid of that by using the AGGREGATE function with the ignore errors argument set after we do change the equality test to 1/(Transactions[Category]=I12) which will create DIV/0 errors for the non-matchers.
Putting it all together
=SUM(INDEX(Transactions[Out],AGGREGATE(15,6,1/(Transactions[Category]=I12)*ROW(Transactions)-ROW(Transactions[#Headers]),ROW(INDIRECT("1:"&COUNTIF(Transactions[Category],$I$12))))))
You may need to enter this with CSE depending on your version of Excel.
Also, if you have a lot of these formulas, you may want to change the k argument for AGGREGATE to use the INDEX function (non-volatile) instead of the volatile INDIRECT function.
=SUM(INDEX(Transactions[Out],AGGREGATE(15,6,1/(Transactions[Category]=I12)*ROW(Transactions)-ROW(Transactions[#Headers]),ROW(INDEX($A:$A,1,1):INDEX($A:$A,COUNTIF(Transactions[Category],$I$12),1)))))
Edit
If you have Excel/O365 with dynamic arrays and the FILTER function, you can greatly simplify the above to the normally entered:
=SUM(FILTER(Transactions[Out],Transactions[Category]=I12))
First question here, thanks in advance for your patience and assistance!
I have a spreadsheet that contains course types (column A, e.g. "Lec" or "Dis"), enrollment numbers (column B, as integers), and session times (column C, string time interval e.g. "10:00AM - 01:00PM").
I need to sum the enrollment numbers for all classes of a certain type (say "Lec") that end before a certain time (say 3:00 PM). The following code accomplishes that:
=SUMPRODUCT(--((A2:A8="Lec")), --(TIMEVALUE(MID(B2:B8,11,5)&" "&MID(B2:B8,16,2))<=TIMEVALUE("03:00 PM")), C2:C8)
The problem is that some of the session times may be blank, which renders a "#VALUE!" error. As best I can tell this is because TIMEVALUE is unable to accept an empty cell as input, so whenever that occurs it breaks the whole thing. I therefore need in this case for the formula to ignore the row and not progress to the various other evaluations.
I have attempted to protect the TIMEVALUE content behind various conditional statements, e.g. only considering that row if the time session length is correct (length=17). I have not been able to do this successfully, however. Nor have my internet searches found a similar-enough situation to use for help.
Because of the circumstances around this project, I am strongly interested in formula solutions before considering things like changing the overall spreadsheet format or adding dummy columns for computations. That said, I welcome any and all suggestions!
Unfortunately, using AGGREGATE as SUM does not skip errors if there is a Calculation in the formula. Similarly, IFERROR and ISERROR only work properly with Ranges/Arrays when in an Array Formula, not when in SUMPRODUCT. That's the easiest options out unless you want a calculation column.
However, all is not lost! First, we reduce your SUMPRODUCT to a single argument with * in place of ,:
=SUMPRODUCT(--(A2:A8="Lec")*--(TIMEVALUE(MID(B2:B8,11,5)&" "&MID(B2:B8,16,2))<=TIMEVALUE("03:00 PM"))*C2:C8)
Next, we change this from =SUMPRODUCT(X) to =SUM(IFERROR(X,0)):
=SUM(IFERROR(--(A2:A8="Lec")*--(TIMEVALUE(MID(B2:B8,11,5)&" "&MID(B2:B8,16,2))<=TIMEVALUE("03:00 PM"))*C2:C8),0)
Just remember to press [Ctrl]+[Shift]+[Enter] instead of just [Enter] to convert to an Array Formula - the formula will display in {Curly brackets}
Basically I am trying to improve a spreadsheet that current uses fixed IF functions within IF functions to determine where to find data, then originally used the VLOOKUP function to return the appropriate cable cleat size. Where "Cleat Diameter">"Cable Diameter".
I've been using this for a while, however excel quickly runs out of resources with all the remaining calculations being performed. As a result, I've opted to put all data a single table, and try to use the match function to retrieve the necessary row. Then Simply use the =INDIRECT function to retrieve data from the appropriate column of the associated row.
Unfortunately I believe the issue relates to the fact that I first need to perform at MATCH Type 0 (exact match), followed by a type -1 for the size to identify the next size up that can accommodate a specific cable size.
I've managed a simple lookup on another dataset using (for exact matches):
=MATCH($B3,'Current Raw Data'!A:A,0)+ROW('Current Raw Data'!A:A)-1
However when I attempt the same thing with two types of matches I get errors. The closest I get it using the following array formula, but it does not work unless the data set is arranged so that the contents of Cell C3 is the first occurring item in the dataset in column A:A:
{=MATCH(C3,($B3='Lookup - Cleats'!A:A)*('Lookup - Cleats'!B:B),-1)}
Main sheet:
Dataset Example:
With this array formula (click Ctrl + Shift + Enter together inside formula bar), you should be able to get your results:
=IFERROR(INDEX('Lookup - Cleats'!C$3:C$26,MATCH($B3&$C3,'Lookup - Cleats'!$A$3:$A$26&'Lookup - Cleats'!$B$3:$B$26,0)),"")
I tried my best to use your data setup but maybe miss one or two things that you will need to adjust accordingly. Let me know if this is not working.
NOTE: I don't need a solution for the actual problem to be solved with Excel. I want to understand and discuss the behaviour. And I want to see, if other people can reproduce the situation and make them aware of it.
Situation is extremely simplified for debugging the problem.
I use Excel 2007 in an cooperate environment
In a calculation made on a two-week basis, I have to fill in numbers for the two-week interval that are valid a whole month. For example first two weeks of December I have to use value 12, second two weeks again, than first to weeks of January I have to use 1, second two weeks again.
Therefore I have a column for each two-week period with a field of current month (green area in screenshot). The values valid for the month are in a second table (red area). To retrieve the value for current period, I use a LOOKUP()call:
(A2): =LOOKUP(A1;$A$9:$H$9;$A$10:$H$10)
...
(P2): =LOOKUP(P1;$A$9:$H$9;$A$10:$H$10)
As you can see in the screenshot, the function goes havoc and retrieves false values.
For testing, I reproduced the situation with the international phonetic alphabet instead of month names. Therefore:
(A5): =LOOKUP(A4;$A$12:$H$12;$A$13:$H$13)
...
This time, the function works well. Therefore I guess, it has something to do with the name of months. Maybe they have some internal representation, despite the fact, the cell are formatted as "text".
I already tested vertical vectors instead of horizontals in the red area. They lead to the same situation.
NOTE:
I finally solved the original problem by using HLOOKUP() and VLOOKUP(). There I found another clue. Both show the same behaviour if [not_exact_match] is committed or set to true but work fine, if exact_match is enforced. So, how can Februar be an approximate match to Dezember?
See http://office.microsoft.com/en-gb/excel-help/lookup-function-HP010342671.aspx
For the LOOKUP function to work correctly, the data being looked up must be sorted in ascending order.
This is not the case with the texts "Dezember", "Januar", "Februar", ...
If you would use real dates 01.12.2013, 01.01.2014, 01.02.2014, ... and format them as "MMMM", then it should work. Of course the lookup_value also has to be in that form.
Same problem with VLOOKUP and not exact match. http://office.microsoft.com/en-gb/excel-help/vlookup-function-HP010343011.aspx
If range_lookup is either TRUE or is omitted, the values in the first column of table_array must be placed in ascending sort order; otherwise, VLOOKUP might not return the correct value.