Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

find row number of first cell in a relative range that is less than $B$3

Thanks for any help. I've spent hours searching, trying, and reading iWork Help


Example: $B$3 = 3


Column C

1: 9

2: 2

3: 9

4: 2

5: 3

6: 9

7: 9



Find the first occurrence that is less than $B$3 (=3) in the range C3:C6. Return the row # (relative to the range, or actual row number, I don't care)

Fill Down the formula, so the next cell looks at the range C4:C7


In this case, I want it to return Row 4 (not 5 or 2)


Tried this with MATCH (last argument -1 or 1) which almost works, but if it finds an exact match, it returns that row (5) instead of the first one (4)

iWork Numbers-OTHER

Posted on Jun 26, 2011 3:22 PM

Reply
12 replies

Jun 26, 2011 4:59 PM in response to RJ mac

Here's an answer to your initial question:

User uploaded file


The result formula (shown) returns the minimum value in the three cells of column D ending with the row on which the formula sits. The IF part of the formula suppresses the result where the three rows are 'empty'.


D2 contains the formula: =IF(C>$B$3,"",ROW())

This returns a null string where the corresponding column C value is greater than the value in B3, or the Row number where the value in C is less than or equal to the value in B3. Column D may be hidden or moved to a separate table if needed.


Regards,

Barry

Jun 26, 2011 5:09 PM in response to RJ mac

And here's a modification that returns the date rather than the row number.


The layout is a little confusing, as I've left the results cells in the same space and added a Dates in column A.


User uploaded file

The only formula change is shown on the table. This formula is filled down to the rest of column B.


Details on all of the functions used is available in the iWork Formulas and functions User Guide, which can be downloadd via the Help menu in Numbers.


Regards,

Barry

Jun 26, 2011 5:42 PM in response to Barry

Thanks for looking at this Barry. If I'm following the logic, it would require one column (like D in this example) for every set of rows searched (in my example, B5:B15 filled down, so the next search is B6:B16 and so on).


Please correct me if I'm wrong.


I have many hundreds of rows of data to search, and the comparison cell ($B$3) must be able to change for a new set of results. I think that may push Numbers to the limit or beyond.


-RJ

Jun 26, 2011 7:53 PM in response to RJ mac

The single formula in D2, filled down that column, returns the row number of every row where the value in column C is less than or equal to the value in $B$3.


The second formula, which I placed in B4, but which can go wherever it's needed, searches a limited range of column D for the minimum value in that range.


In the example, based on your initial question, the range is three cells. In B4, it's D2:D4; in B5 it's D3:D5, etc., with Numbers automatically adjusting the cell references as the formula is filled down the column. In each case, the formula returns the minimum value it finds in the three cell range, which is the row number on which the value in column C first meets the condition (less than or equal to $B$3) within that three cell range.


In the second example, the formula retrieves the same value (the row number) as above, but instead of displaying it, uses it as the row-offset value in an OFFSET statement to return the Date from the row where the row number was collected.


NOTE: Looking back at it, I see that in my rush to other duties I made an error in this formula, setting the row offset too high. Revise the formula as shown below to get the date from the correct row:


Existing: =IF(MAX(D2:D4)=0,"",OFFSET($A$1,MIN(D2:D4),0))


Revised: =IF(MAX(D2:D4)=0,"",OFFSET($A$1,MIN(D2:D4)-1,0))


You wrote:

If I'm following the logic, it would require one column (like D in this example) for every set of rows searched (in my example, B5:B15 filled down, so the next search is B6:B16 and so on).


No. Provided the values of X and Y are constant for each set of searches, you'll need an auxiliary column for each column of values to be searched. One auxiliary column is used to mark the rows in which the value in B meets the condition ">x", the second to mark the rows where the value in C meets the condition "<y".


The search formula (above) searches a subset of its column and returns the lowest row number where the condition for that column is met,and either displays that number or uses it to return and display a date.


Regards,

Barry

Jun 26, 2011 9:28 PM in response to Barry

Barry wrote:


No. Provided the values of X and Y are constant for each set of searches, you'll need an auxiliary column for each column of values to be searched. One auxiliary column is used to mark the rows in which the value in B meets the condition ">x", the second to mark the rows where the value in C meets the condition "<y".



Well, shoot. I didn't explain it well enough in the first place. Unfortunately, X and Y do change... at every row, going down for hundreds of rows.


We're communicating on the other part fine:

I'm looking for the FIRST occurrence in Range A that is > X

to check if it's earlier than the FIRST occurrence in Range B that is < Y


thus the idea of comparing the position in the array / row #. Date compare would work too.

Jun 26, 2011 11:02 PM in response to RJ mac

RJ mac wrote:

Well, shoot. I didn't explain it well enough in the first place. Unfortunately, X and Y do change... at every row, going down for hundreds of rows.

So the reference in the initial question should not have been to the fixed cell $B$3. 😉


What is the possible range of the values of X and Y? Are they, as suggested in the initial post, integer values? If not, can the X and Y values be treated as a range of discrete values?


Is the search range at each step 11 cells?


Regards,

Barry

Jun 27, 2011 9:44 AM in response to Barry

Yes, sorry... The second "original" post was a bit more clear. The fixed cell $B$3 is subtracted from every Y value and then I want to find the first occurrence that is less than that in the 11 cells in Range B


In other words, =row(firstOccurrence(B10:B20<(Y-$B$3) ) ) 😝


which generates several errors, not the least of which is "A10:A20 cannot be used as a single number"

(and it needs a "" or zero for when it finds no matches)


or...


=MATCH(Y10,A10:A20,-2)

(-2 is the imaginary future argument that means "find the first value smaller than arg1)

all we have now are -1 0 and 1


To answer your other questions, X and Y are NOT integers, and they are "random" and in jumbled order.


Thank you for your time!

Jun 27, 2011 11:05 AM in response to Barry

As much as I hate my PC, I found the solution in OpenOffice:


=MATCH(TRUE,A10:A20<B$3,0)

ctrl-shift-enter (to commit an Array formula) which then surrounds the formula in braces


...except O.O. uses semi-colons instead of commas. Filter the #N/A results with =ISNA(cell)


This same thing in Numbers seems to only search the first cell, or reports it can't find it, or says that A10:A20 cannot be used as a single number.


I'd rather not resort to using my P.C. so I hope I'm missing something in Numbers. (Mac NeoOffice just plain ***** and I've caught it making many large math errors)

Jun 27, 2011 12:39 PM in response to RJ mac

The iWork Formulas and Functions User Guide has very little to say about "array functions":


A small number of functions are described as

“array function,” meaning the function returns an

array of values rather than a single value. These

functions are commonly used to provide values

to another function.


MATCH does not seem to be one of this "small number," according to its description in the same guide. 😟


OOo (OpenOffice.org—the application's name includes the.org for reasons explained at the website) is available for Mac OS 10.5.8 and newer, starting with version 3.0.


Regards,

Barry

find row number of first cell in a relative range that is less than $B$3

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.