Numbers Formulas Help

Hi can anyone help with the correct formula? Thanks,


See attached screen shot.


After I have manually inserted the $ values in Table 1, I would like the corresponding % from Table 1 column A to be automatically input into table 2 column B. However, you will notice that the $ values do not exactly match between the two tables therefore I only want the corresponding % value in table 1 column A to be displayed in table 2 column B if it is within +/- (10%) of the dollar value in table 1 Column A. If not display nothing in table 2 column B.


MacBook Air 13″, macOS 11.3

Posted on May 21, 2021 10:05 PM

Reply
Question marked as Top-ranking reply

Posted on May 22, 2021 2:19 AM

Copy of reply to your other post containing this question.


The difficulty here is that there is no function that will do the search directly for a value that is "within ±10% of a target.



MATCH, which is the search functionI used here, is capable of finding the largest value less than or equal to the search value, or of finding the smallest value more than or equal to the search value, or of requiring an exact match of the search value.


A formula using this talent of MATCH, and adding INDEX to return the matching percentage, and a table containing two auxiliary columns to show the upper and lower limits of the values acceptable to meet the ±10% requirement can be constructed as shown in the example below:





The formula is entered as shown in cell B2 of Table 2, then filled down to the last cell in that column.


IFERROR(IF(INDEX(Table 1::A,MATCH(A2,Table 1::C,1),)=INDEX(Table 1::A,MATCH(A2,Table 1::D,−1)),INDEX(Table 1::A,MATCH(A2,Table 1::B,1),),""),"n/a")


The formula uses this pair of functions, MATCH and INDEX to look up a percentage in Table 1 twice to determine if there is a match that is within the ±10% range. If the first search (of column C for a number less than or equal to the value being searched) and the second (of column D for a number greater than or equal to the value being searched) both return the same row number (and consequently the same percentage value, IF repeats the first search and returns the value it finds.


If the two Match and INDEX searches return different values, the comaparison returns FALSE, and IF returns a null string, making the cell containing the formula appear blank.


The whole formula (bold part) returns an error if either MATCH returns a 'can't Find error. This error message is caught by IFERROR, which returns the "n/a" text string seen in the bottom rows of column B of Table 2.


I would leave this (not bolded) part out while constructing and testing the formula (bold part) until you have that part error free (except fo the expected error which will occur in the cells showing "n/a" in the example.


You can find details regarding the three functions used in the Function Browser.


Regards,

Barry

7 replies
Question marked as Top-ranking reply

May 22, 2021 2:19 AM in response to NickB2708

Copy of reply to your other post containing this question.


The difficulty here is that there is no function that will do the search directly for a value that is "within ±10% of a target.



MATCH, which is the search functionI used here, is capable of finding the largest value less than or equal to the search value, or of finding the smallest value more than or equal to the search value, or of requiring an exact match of the search value.


A formula using this talent of MATCH, and adding INDEX to return the matching percentage, and a table containing two auxiliary columns to show the upper and lower limits of the values acceptable to meet the ±10% requirement can be constructed as shown in the example below:





The formula is entered as shown in cell B2 of Table 2, then filled down to the last cell in that column.


IFERROR(IF(INDEX(Table 1::A,MATCH(A2,Table 1::C,1),)=INDEX(Table 1::A,MATCH(A2,Table 1::D,−1)),INDEX(Table 1::A,MATCH(A2,Table 1::B,1),),""),"n/a")


The formula uses this pair of functions, MATCH and INDEX to look up a percentage in Table 1 twice to determine if there is a match that is within the ±10% range. If the first search (of column C for a number less than or equal to the value being searched) and the second (of column D for a number greater than or equal to the value being searched) both return the same row number (and consequently the same percentage value, IF repeats the first search and returns the value it finds.


If the two Match and INDEX searches return different values, the comaparison returns FALSE, and IF returns a null string, making the cell containing the formula appear blank.


The whole formula (bold part) returns an error if either MATCH returns a 'can't Find error. This error message is caught by IFERROR, which returns the "n/a" text string seen in the bottom rows of column B of Table 2.


I would leave this (not bolded) part out while constructing and testing the formula (bold part) until you have that part error free (except fo the expected error which will occur in the cells showing "n/a" in the example.


You can find details regarding the three functions used in the Function Browser.


Regards,

Barry

May 22, 2021 5:07 AM in response to NickB2708

You may want to rethink this a bit.


+/-10% ends up with a whole lot of overlap.

+/-10% of your lowest number 70 is 63 to 77

+/-10% of the next number 80 is 72 to 88

Any match from 72-77 will appear on both rows

+/-10% of your highest number 310 = 279 to 341

This overlaps several rows, which all also overlap each other.

The middles rows overlap in both directions. They are the worst.


Maybe you want +/-5 instead, as in (A-5)<=match<(A+5)


Add a new column to Table 1 with the formula =ROUND(B,-1)

This will round your values to the nearest ten dollars. Now you can use XLOOKUP from Table 2

=XLOOKUP(A,Table 1::C,Table 1::A,"",0)

Note that if two rows in Table 1 round to the same number, one is going to get dropped, it will not make it over to Table 2. If you want them both included, you can add the percentages together vs doing a lookup. Use SUMIF instead of XLOOKUP.

=SUMIF(Table 1::C,A,Table 1::A)

or, to blank out the zeros,

=IF(SUMIF(Table 1::C,A,Table 1::A)=0,"",SUMIF(Table 1::C,A,Table 1::A))

May 23, 2021 12:52 AM in response to NickB2708

HI Nick,


"Thanks Barry, when I pasted the formula, it just gave me N/A. "


That's odd. I would expect it to give the same results as I got, unless you were using different values in columns. As can be seen in the images in my reply to your other statement of this question (here: Numbers Functions/Formulas Help - Apple Community ), the only "n/a" results I received were for values in column A of the second table greater than 237, the +10% value for 216, the largest test value liste in the first table.


The copy of that response in this discussion was placed here using copy — paste, and dropped the images I'd included with the original.


Regards,

Barry

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Numbers Formulas Help

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