my_sunshine
New Member
- Joined
- Sep 28, 2016
- Messages
- 5
Hi all,
I hope you can help me to extract a new data table with all the fields from the attached product order data, using Access SQL or Access Design View. Please note each ID has one (ID 16) or more quotes (ID 13) and the quotes within an ID can be the same (A1) or different (A2-A4) but each row of data is an unique combination of the columns' values. The data is selected based on the Primary (0 or 1), Last change date, and no Product B nor Product C.
[TABLE="width: 600"]
<colgroup><col span="4"><col><col span="2"></colgroup><tbody>[TR]
[TD]ID[/TD]
[TD]Judgment[/TD]
[TD]Primary[/TD]
[TD]Quote[/TD]
[TD]Products[/TD]
[TD]Quantity[/TD]
[TD]Last change date[/TD]
[/TR]
[TR]
[TD="align: right"]13[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1 [/TD]
[TD]A1[/TD]
[TD]Product A[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]8/8/2016[/TD]
[/TR]
[TR]
[TD="align: right"]13[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1 [/TD]
[TD]A1[/TD]
[TD]… Product B ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/8/2016[/TD]
[/TR]
[TR]
[TD="align: right"]13[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]0 [/TD]
[TD]A2[/TD]
[TD]Product D Level 3[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]8/17/2016[/TD]
[/TR]
[TR]
[TD="align: right"]13[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]0[/TD]
[TD] A3[/TD]
[TD]… Product B ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/17/2016[/TD]
[/TR]
[TR]
[TD="align: right"]13[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]0[/TD]
[TD] A4[/TD]
[TD]… Product B ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]16[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]0 [/TD]
[TD]A5[/TD]
[TD]Product D Level 3[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A6[/TD]
[TD]… Product B ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/20/2016[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A15[/TD]
[TD]Product D Level 3[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]8/17/2016[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A7[/TD]
[TD]Product A[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A7[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A7[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A7[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A7[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A7[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A7[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A8[/TD]
[TD]Product A[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A8[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A9[/TD]
[TD]Product A[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A9[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A10[/TD]
[TD]Product A[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1 [/TD]
[TD]A10[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A11[/TD]
[TD]Product A[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A11[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A11[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A11[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A11[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A11[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A12[/TD]
[TD]Product A[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A12[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A12[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A12[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A12[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A12[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A12[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1 [/TD]
[TD]A13[/TD]
[TD]Product A[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]
[TD] A13[/TD]
[TD]Product D Level 3[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A14[/TD]
[TD]Product A[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A14[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A16[/TD]
[TD]Product A[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A16[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A16[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A16[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A16[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A16[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]18[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]
[TD] a17[/TD]
[TD]… Product B ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]18[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] a17[/TD]
[TD]… Product B ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]18[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1 [/TD]
[TD]a17[/TD]
[TD]… Product B ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]18[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] a18[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]18[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] a18[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]18[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] a18[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
</tbody>[/TABLE]
The criteria are:
1) If an ID has only 1 quote with Primary = 0, and no Product B nor Product C, e.g. ID 16, we'll keep ID 16 quote A5 Product D level 3.
2) If an ID has multiple quotes with all the Primary = 0, e.g. ID 17, choose the quote with the latest Last Change date (8/27/16) and no Product B nor Product C. In this case, we'll keep ID 17 quote A7 Product A.
3) If an ID has all the Products = Product B or Product C, we'll NOT keep the ID e.g. ID 18.
4) If an ID has multiple quotes with more than 1 quote of Primary = 1 e.g. ID 13, we'll keep the ID that has no Product B nor Product C. In this case ID 13 quote A1 Product A, ID 15 quote A13 Product A and Product D Level 3 will be keep.
5) If an ID has multiple quotes and the quote with Primary = 1 has Product B or C, we will NOT keep the ID e.g. ID 14.
After the new data table is created, I'd like to add a new field (named Level 3) to the table to count the quantity of Level 3 for each ID, and subtract the same quantity from the Quantity field.
The new table will look like this:
[TABLE="width: 599"]
<colgroup><col span="4"><col><col><col><col></colgroup><tbody>[TR]
[TD]ID[/TD]
[TD]Judgment [/TD]
[TD]Primary[/TD]
[TD]Quote[/TD]
[TD]Products[/TD]
[TD]Quantity[/TD]
[TD]Level 3[/TD]
[TD]Last change date[/TD]
[/TR]
[TR]
[TD="align: right"]13[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD] A1[/TD]
[TD]Product A[/TD]
[TD="align: right"]4[/TD]
[TD][/TD]
[TD="align: right"]8/8/2016[/TD]
[/TR]
[TR]
[TD="align: right"]16[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]0[/TD]
[TD] A5[/TD]
[TD]Product D Level 3[/TD]
[TD][/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A7[/TD]
[TD]Product A[/TD]
[TD="align: right"]2[/TD]
[TD][/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]
[TD] A13[/TD]
[TD]Product A[/TD]
[TD="align: right"]2[/TD]
[TD][/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]
[TD] A13[/TD]
[TD]Product D Level 3[/TD]
[TD][/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
</tbody>[/TABLE]
Please help! Thank you so so so much!
I hope you can help me to extract a new data table with all the fields from the attached product order data, using Access SQL or Access Design View. Please note each ID has one (ID 16) or more quotes (ID 13) and the quotes within an ID can be the same (A1) or different (A2-A4) but each row of data is an unique combination of the columns' values. The data is selected based on the Primary (0 or 1), Last change date, and no Product B nor Product C.
[TABLE="width: 600"]
<colgroup><col span="4"><col><col span="2"></colgroup><tbody>[TR]
[TD]ID[/TD]
[TD]Judgment[/TD]
[TD]Primary[/TD]
[TD]Quote[/TD]
[TD]Products[/TD]
[TD]Quantity[/TD]
[TD]Last change date[/TD]
[/TR]
[TR]
[TD="align: right"]13[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1 [/TD]
[TD]A1[/TD]
[TD]Product A[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]8/8/2016[/TD]
[/TR]
[TR]
[TD="align: right"]13[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1 [/TD]
[TD]A1[/TD]
[TD]… Product B ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/8/2016[/TD]
[/TR]
[TR]
[TD="align: right"]13[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]0 [/TD]
[TD]A2[/TD]
[TD]Product D Level 3[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]8/17/2016[/TD]
[/TR]
[TR]
[TD="align: right"]13[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]0[/TD]
[TD] A3[/TD]
[TD]… Product B ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/17/2016[/TD]
[/TR]
[TR]
[TD="align: right"]13[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]0[/TD]
[TD] A4[/TD]
[TD]… Product B ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]16[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]0 [/TD]
[TD]A5[/TD]
[TD]Product D Level 3[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A6[/TD]
[TD]… Product B ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/20/2016[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A15[/TD]
[TD]Product D Level 3[/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]8/17/2016[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A7[/TD]
[TD]Product A[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A7[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A7[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A7[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A7[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A7[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A7[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A8[/TD]
[TD]Product A[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A8[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A9[/TD]
[TD]Product A[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A9[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A10[/TD]
[TD]Product A[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1 [/TD]
[TD]A10[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A11[/TD]
[TD]Product A[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A11[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A11[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A11[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A11[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]14[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A11[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A12[/TD]
[TD]Product A[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A12[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A12[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A12[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A12[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A12[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A12[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1 [/TD]
[TD]A13[/TD]
[TD]Product A[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]
[TD] A13[/TD]
[TD]Product D Level 3[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A14[/TD]
[TD]Product A[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A14[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A16[/TD]
[TD]Product A[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A16[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A16[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A16[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0 [/TD]
[TD]A16[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A16[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]18[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]
[TD] a17[/TD]
[TD]… Product B ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]18[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] a17[/TD]
[TD]… Product B ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]18[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1 [/TD]
[TD]a17[/TD]
[TD]… Product B ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]18[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] a18[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]18[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] a18[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]18[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] a18[/TD]
[TD]… product C ….[/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
</tbody>[/TABLE]
The criteria are:
1) If an ID has only 1 quote with Primary = 0, and no Product B nor Product C, e.g. ID 16, we'll keep ID 16 quote A5 Product D level 3.
2) If an ID has multiple quotes with all the Primary = 0, e.g. ID 17, choose the quote with the latest Last Change date (8/27/16) and no Product B nor Product C. In this case, we'll keep ID 17 quote A7 Product A.
3) If an ID has all the Products = Product B or Product C, we'll NOT keep the ID e.g. ID 18.
4) If an ID has multiple quotes with more than 1 quote of Primary = 1 e.g. ID 13, we'll keep the ID that has no Product B nor Product C. In this case ID 13 quote A1 Product A, ID 15 quote A13 Product A and Product D Level 3 will be keep.
5) If an ID has multiple quotes and the quote with Primary = 1 has Product B or C, we will NOT keep the ID e.g. ID 14.
After the new data table is created, I'd like to add a new field (named Level 3) to the table to count the quantity of Level 3 for each ID, and subtract the same quantity from the Quantity field.
The new table will look like this:
[TABLE="width: 599"]
<colgroup><col span="4"><col><col><col><col></colgroup><tbody>[TR]
[TD]ID[/TD]
[TD]Judgment [/TD]
[TD]Primary[/TD]
[TD]Quote[/TD]
[TD]Products[/TD]
[TD]Quantity[/TD]
[TD]Level 3[/TD]
[TD]Last change date[/TD]
[/TR]
[TR]
[TD="align: right"]13[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]1[/TD]
[TD] A1[/TD]
[TD]Product A[/TD]
[TD="align: right"]4[/TD]
[TD][/TD]
[TD="align: right"]8/8/2016[/TD]
[/TR]
[TR]
[TD="align: right"]16[/TD]
[TD="align: right"]1[/TD]
[TD="align: right"]0[/TD]
[TD] A5[/TD]
[TD]Product D Level 3[/TD]
[TD][/TD]
[TD="align: right"]4[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]17[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]0[/TD]
[TD] A7[/TD]
[TD]Product A[/TD]
[TD="align: right"]2[/TD]
[TD][/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]
[TD] A13[/TD]
[TD]Product A[/TD]
[TD="align: right"]2[/TD]
[TD][/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
[TR]
[TD="align: right"]15[/TD]
[TD="align: right"]0[/TD]
[TD="align: right"]1[/TD]
[TD] A13[/TD]
[TD]Product D Level 3[/TD]
[TD][/TD]
[TD="align: right"]2[/TD]
[TD="align: right"]8/27/2016[/TD]
[/TR]
</tbody>[/TABLE]
Please help! Thank you so so so much!