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

search two tables for criteria to populate third table

Hello -


I am very new to Numbers and the Support Communities. I have read help and searched this forum but cannot find a similar question. I appreciate any advice or suggestions.


I have created two numbers table from our client database, and am trying to process it as follows: (see example below)


Goal: Create a third table, that contains the invoice number, date, invoice total and owner state of residency, as long as the invoice DOES NOT contain certain invoice items.


In the example below, I made up invoice items ITEM-YES and ITEM-NO; there are actual items in the database that I want to look for and disregard those invoices that contain the ITEM-NO item all together.


Table 1 (invoice totals):

Invoice # Date Invoice Total Owner State

1 12/1/15 $800.00 NC

2 12/2/15 $125.00 FL

3 12/5/15 $300.00 NY

4 12/9/15 $500.00 CA



Table 2: (individual items that make up the invoice)

Invoice # Item Item Cost

1 ITEM-YES $200.00

1 ITEM-YES $100.00

1 ITEM-YES $500.00

2 ITEM-YES $25.00

2 ITEM-NO $100.00

3 ITEM-YES $300.00

4 ITEM-YES $400.00

4 ITEM-NO $100.00



The RESULTS table based on the above should look like:


Table Results:

Invoice # Date Invoice Total Owner State

1 12/1/15 $800.00 NC

3 12/5/15 $300.00 NY



Thank you very much for your advice and guidance.

MacBook Pro (13-inch Mid 2012), OS X El Capitan (10.11.3)

Posted on Feb 5, 2016 9:48 PM

Reply
8 replies

Feb 5, 2016 11:25 PM in response to ufgatorvet

Hi 'gator,


You wrote: "as long as the invoice DOES NOT contain certain invoice items."


But in your example, you showed two invoices containing the same 'certain invoice item.'


In practice, will you be omitting invoices which contain one specific item, or will you be omitting invoices which contain one or more items from a list of several items?


Regards,

Barry

Feb 6, 2016 9:13 AM in response to ufgatorvet

Hi,


I think something like this will do what you want:


User uploaded file



Add a filter column to Table 1 with this formula in E2, copied down:


=COUNTIFS(Table 2::A,A2,Table 2::B,E$1)


The value in E$1 must be spelled exactly like the invoice item you want to use to exclude invoices.


Then filter on 0 in column E. Select the cells, command c to copy, click once in a cell in a new table and Edit > Paste Formula results.


SG

Feb 6, 2016 2:04 PM in response to ufgatorvet

If you don't like the manual copy-pasting and want the Results table to generate and update automatically, here's a slightly fancier solution:User uploaded file


The formula in E2, filled down, is:


=IF(COUNTIFS(Table 2::A,A2,Table 2::B,E$1)>0,"",MAX(E$1:E1)+1)


This increments a counter each time it sees there are no matches for ITEM-NO and invoice number in Table 2.


Then you can use that counter to fill in the Results table with this formula, input into A2, and filled right and down:


User uploaded file


=INDEX(Table 1::A,MATCH(ROW()−1,Table 1::$E,0))


The INDEX MATCH combination is simply a form of lookup. Here it looks for a match of the row number the formula is on (minus 1 because there is one Header Row) in column E of Table 1 and returns the value from column A on that same row. When you fill it right it returns the value from column B, column C, etc.


To hide the red warning triangles in cells that are out of range because there are more rows in the Results than there are matches you can wrap this formula in IFERROR, like this:


=IFERROR(INDEX(Table 1::A,MATCH(ROW()−1,Table 1::$E,0)),"")


SG

Feb 6, 2016 3:25 PM in response to Yellowbox

Hi -


Thank you so much for taking the time to assist me.


For completeness and clarification, I created tables with real data (although some sensitive columns were removed for privacy reasons).


There is a main Invoice Table that contains the details of each invoice including the grand total of the invoice.


ID

DateCreated

TimeCreated

ClientID

GrandTotal

8039

1/20/13

15:52:27

2

1266

8514

1/20/13

19:03:53

2

1498.06

9447

1/20/13

19:28:52

2

125

13960

1/23/13

10:33:18

10

450

14062

1/23/13

11:30:32

10

450

14502

1/23/13

13:46:59

11

450

15413

1/23/13

16:14:41

11

552.16


And there is an Invoice Line Item table that lists all the individual items that make up each invoice. In the following table, "InvoiceID" links to the first table ("ID" in the above table):


ID

DateCreated

TimeCreated

InvoiceID

Patient_ID

Code

Price

8040

1/20/13

15:40:43

8039

2

PS1500

125

8042

1/20/13

15:40:43

8039

2

CF1400

48

8515

1/20/13

19:00:01

8514

2

PS1600

180

8519

1/20/13

19:00:01

8514

2

US2300

325

8521

1/20/13

19:00:01

8514

2

PS1500

125

8523

1/20/13

19:00:01

8514

2

PS1200

180

8525

1/20/13

19:00:01

8514

2

PS1300

70

8527

1/20/13

19:00:01

8514

2

PS1400

95

8044

1/20/13

15:40:43

8039

2

CF3100

30.8

8046

1/20/13

15:40:43

8039

2

Ho1800

160

8048

1/20/13

15:40:43

8039

2

XX1100

2.01

8050

1/20/13

15:40:43

8039

2

IM1650

14.07

8052

1/20/13

15:40:43

8039

2

PS1950

31.75

8054

1/20/13

15:40:43

8039

2

LaH3200

11

8056

1/20/13

15:40:43

8039

2

LaH1450

34

8058

1/20/13

15:40:43

8039

2

LaH1500

70.56

8060

1/20/13

15:40:43

8039

2

LaH2400

18.63

8062

1/20/13

15:40:43

8039

2

LaH4050

45

8064

1/20/13

15:40:43

8039

2

LaH1250

31.25

8066

1/20/13

15:40:43

8039

2

CF2300

144.06

8068

1/20/13

15:40:43

8039

2

CF2400

0.25

8070

1/20/13

15:40:43

8039

2

CF2800

28.21

8072

1/20/13

15:40:43

8039

2

Rx2400

1.02

8074

1/20/13

15:40:43

8039

2

Rx2425

35.1

8076

1/20/13

15:40:43

8039

2

CF1600

14

8078

1/20/13

15:40:43

8039

2

US2300

325

8531

1/20/13

19:00:01

8514

2

CF2300

144.06

8533

1/20/13

19:00:01

8514

2

CF3100

30.8

8535

1/20/13

19:00:01

8514

2

CF2700

37.05

8537

1/20/13

19:00:01

8514

2

CF2800

28.21

8539

1/20/13

19:00:01

8514

2

IM2100

95

8541

1/20/13

19:00:01

8514

2

IM1850

1.53

8543

1/20/13

19:00:01

8514

2

LaH2400

18.63

8545

1/20/13

19:00:01

8514

2

LaH1450

34

8547

1/20/13

19:00:01

8514

2

LaH1400

62

8549

1/20/13

19:00:01

8514

2

LaH2100

20

8551

1/20/13

19:00:01

8514

2

Dx1700

35

8553

1/20/13

19:00:01

8514

2

Dx3500

21

9448

1/20/13

19:28:39

9447

2

PS1500

125

13961

1/23/13

10:32:11

13960

13

PS1500

125

14165

1/23/13

12:02:21

14062

13

US2300

325

13965

1/23/13

10:32:11

13960

13

US2300

325

14063

1/23/13

11:48:01

14062

13

XX1500

125

14503

1/23/13

13:46:34

14502

14

PS1500

125

14505

1/23/13

13:46:34

14502

14

XX2300

325

15414

1/23/13

16:14:50

15413

14

PS1500

125

15416

1/23/13

16:14:58

15413

14

US2300

325

15418

1/23/13

16:15:11

15413

14

IM1500

18.51

15542

1/23/13

17:52:25

15413

14

US1200

48

15544

1/23/13

17:52:33

15413

14

LaH2150

38


I want to create a results table that contains the invoice ID, date invoice created and the grand total of any invoice (in the first table) that does NOT contain a code that begins with "XX". So in this abbreviated example, the results table should look like:


ID

DateCreated

GrandTotal

8514

1/20/13

1498.06

9447

1/20/13

125

13960

1/23/13

450

14513

1/23/13

552.16


Three of the invoices contained a Code that began with "XX", so those are discarded.


I hope that this makes more sense than my original post.


One of these tables has 20,000 records (and growing by hundreds every day) so obviously manual evaluation is not possible.


I really appreciate your time and expertise!


Thank you,

Jim

Feb 6, 2016 5:48 PM in response to ufgatorvet

Hi Jim,


Did you see my solution above? It gives the result you want:


User uploaded file



Add an extra column in your Table 1. Put XX in the header, and this formula in F2 and fill down.


=IF(COUNTIFS(Table 2::D,A2,Table 2::H,F$1)>0,"",MAX(F$1:F1)+1)


This is a "counter" that increments each time it sees there is no match on XX and that invoice number in Table 2.


In Table 2 add a column, and put this formula in H2, and fill down:


=LEFT(F2,2)


In the 'Results' table, the formula in A2, filled right to B2, and down, is:


=INDEX(Table 1::A,MATCH(ROW()−1,Table 1::$F,0))


The formula in C2, filled down is:


=INDEX(Table 1::E,MATCH(ROW()−1,Table 1::$F,0))


As described above, wrap those two formulas in IFERROR if you want to hide the red warning triangles when you get out of range.


Keep in mind that, unlike Excel, Numbers is not designed to handle large datasets. It's likely to get sluggish.


SG

search two tables for criteria to populate third table

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