Power Query to extract rows based on criteria

ronakchoudhary

New Member
Joined
Jul 28, 2020
Messages
7
Office Version
  1. 365
  2. 2013
Platform
  1. Windows
Hi there,

I have two data sets - one has total quantity and one has all invoice details (Invoice number, Quantity, Date). I need to extract all invoices which comprise of the quantity on hand. Data set as below:

Table 1 - Quantity on Hand:

Item NumberItem DescriptionGSV QTY
00000429a
1​
00000584b
4​
0006648-801c
6​
00076d
1​
00083-002e
331​
00107-072-001f
4​

Table 2 - Invoice Data:

Item NumberItem DescriptionGRN RefGRN DateGRN Qty
00000429a43
03-Jul-13​
1​
00000584b73
16-Dec-09​
3​
00000584b22
11-Dec-09​
13​
00000584b93
22-Jan-10​
13​
00000584b20
02-Mar-10​
26​
00000584b54
10-Jun-10​
13​
00000584b23
10-Jun-10​
13​
00000584b26
22-Jul-10​
10​
00000584b82
02-Sep-10​
1​
00000584b55
02-Sep-10​
1​
00000584b30
02-Sep-10​
1​
00000584b62
02-Sep-10​
1​
00000584b95
02-Sep-10​
1​
00000584b30
02-Sep-10​
1​
00000584b67
02-Sep-10​
1​
00000584b71
02-Sep-10​
1​
00000584b27
02-Sep-10​
1​
00000584b49
02-Sep-10​
1​
00000584b43
22-Sep-10​
1​
00000584b17
22-Sep-10​
1​
00000584b88
22-Sep-10​
1​
00000584b91
22-Sep-10​
1​
00000584b12
22-Sep-10​
1​
00000584b24
22-Sep-10​
1​
00000584b81
22-Sep-10​
1​
00000584b40
22-Sep-10​
1​
00000584b41
22-Sep-10​
1​
00000584b25
22-Sep-10​
1​
00000584b25
22-Sep-10​
1​
00000584b86
22-Sep-10​
1​
00000584b49
22-Sep-10​
1​
00000584b83
22-Sep-10​
1​
00000584b27
22-Sep-10​
1​
00000584b43
22-Sep-10​
1​
00000584b41
22-Sep-10​
1​
00000584b39
22-Sep-10​
1​
00000584b37
22-Sep-10​
1​
00000584b31
22-Sep-10​
1​
00000584b71
06-Nov-10​
1​
00000584b43
06-Nov-10​
1​
00000584b41
06-Nov-10​
1​
00000584b79
06-Nov-10​
1​
00000584b44
06-Nov-10​
1​
00000584b30
06-Nov-10​
1​
00000584b27
06-Nov-10​
1​
00000584b87
06-Nov-10​
1​
00000584b88
06-Nov-10​
1​
00000584b32
06-Nov-10​
1​
00000584b4
06-Nov-10​
1​
00000584b36
06-Nov-10​
1​
00000584b13
06-Nov-10​
1​
0006648-801c59
07-Dec-06​
1​
0006648-801c54
05-Feb-07​
1​
0006648-801c65
22-Sep-06​
1​
0006648-801c88
19-Aug-07​
1​
0006648-801c71
19-Aug-07​
1​
0006648-801c30
11-Feb-05​
1​
0006648-801c61
05-Aug-10​
1​
0006648-801c38
05-Aug-10​
1​
0006648-801c65
26-Dec-10​
1​
0006648-801c13
26-Dec-10​
1​
00076d68
22-Jun-14​
1​
00083-002e96
16-Jul-06​
30​
00083-002e63
23-Jun-06​
30​
00083-002e4
31-Jul-06​
30​
00083-002e84
12-Nov-05​
58​
00083-002e52
01-Nov-05​
62​
00083-002e89
03-Sep-06​
26​
00083-002e19
19-Apr-07​
50​
00083-002e34
06-Mar-07​
40​
00083-002e38
19-Sep-06​
174​
00083-002e25
11-Feb-07​
34​
00083-002e46
03-Dec-06​
34​
00083-002e26
29-Dec-06​
116​
00083-002e79
30-Apr-07​
26​
00083-002e0
13-May-06​
10​
00083-002e83
06-Sep-05​
20​
00083-002e43
27-Feb-05​
30​
00083-002e31
30-Apr-05​
30​
00083-002e59
13-Feb-08​
21​
00083-002e43
05-May-08​
40​
00083-002e41
26-May-08​
27​
00083-002e81
21-Nov-07​
52​
00083-002e64
25-Nov-07​
140​
00083-002e35
06-Jan-08​
87​
00083-002e13
02-Jun-08​
700​
00083-002e33
04-Jul-08​
28​
00083-002e31
21-Jul-08​
172​
00083-002e14
07-May-10​
50​
00083-002e7
14-Jun-10​
75​
00083-002e11
25-Jul-10​
100​
00083-002e77
10-Nov-10​
60​
00083-002e63
25-Nov-10​
40​
00083-002e9
02-Apr-11​
21​
00083-002e91
28-Apr-11​
79​
00083-002e67
28-Jun-11​
49​
00083-002e55
10-Jul-11​
51​
00083-002e22
09-Aug-11​
52​
00083-002e24
13-Aug-11​
48​
00083-002e36
06-Apr-12​
150​
00083-002e46
19-Jul-12​
100​
00083-002e10
10-Aug-12​
100​
00083-002e63
27-Jan-13​
200​
00083-002e79
11-May-13​
26​
00083-002e54
31-May-13​
100​
00083-002e45
10-Jun-13​
34​
00083-002e59
14-Sep-13​
36​
00083-002e85
24-Sep-13​
44​
00083-002e72
28-Oct-13​
80​
00083-002e22
22-Jun-14​
17​
00083-002e78
26-Jun-14​
83​
00083-002e84
24-Nov-14​
100​
00107-072-001f95
22-Feb-14​
4​
00107-072-001f92
31-Oct-16​
2​
00107-072-001f74
28-Jul-19​
2​
00107-072-001f20
07-Mar-20​
2​

Note that total invoice quantity can be higher than, equal to or lower than quantity on hand.

If total quantity in various invoices is equal to quantity on hand, data should pick up all invoices.
If total quantity in various invoices is lower than quantity on hand, data should pick up all invoices.
If total quantity in various invoices is higher than quantity on hand, data should pick up latest invoices (based on date) which make up the quantity on hand.

Can someone help me with how to do this in M Query?

Thanks in advance!!
 
maybe post a link to the shared excel file with your data and code via googledrive, onedrive, dropbox or any similar service
 
Upvote 0

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
see post#11 (preferred) - with sample it will to be hard to say it works slow or fast
or
post example with original structure without any changes (which your code works with)
 
Last edited:
Upvote 0
but before you post example or excel file try
1. add primary key
2. remove duplicates after merge
3. use Table.Buffer (you'll need to find where it will work the best)
4. read this
 
Last edited:
Upvote 0
but before you post example or excel file try
1. add primary key
2. remove duplicates after merge
3. use Table.Buffer (you'll need to find where it will work the best)
4. read this
Hey Sandy, thanks for your feedback. Adding Table.Buffer and primary key really helped. It now takes 3 mins rather than 15 mins. I am guessing 3 mins for a data with over 200,000 rows is justified so living with this. Thanks again for your help. Cheers.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,151
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top