Using FILTER/UNIQUE on text, numbers

danhendo888

Board Regular
Joined
Jul 15, 2019
Messages
142
Office Version
  1. 365
Platform
  1. Windows
I download the below spreadsheet daily from our software. It shows details of invoices paid/booked.
*It doesn't show it below but the first three columns have the little green ribbon on the top left corner of the cell and is aligned to the left of the cell and has General formatting.

Company NumberInvoice NumberOrder NumberOrder DateOrder TaxOrder SubtotalCurrencyPayment Date
1111111111ABC123 y81900901203/12/202410.00100.00AUD
1111111111ABC123 y81900901203/12/202450.00500.00AUD
1111111111ABC123 y81900901203/12/20240.000.00AUD3/14/2024
1111111111ABC123 y81900901203/12/20240.000.00AUD3/14/2024
222222222211122200081900900001/1/20240.0010,000.00AUD


Below is my own spreadsheet. I type in the invoice number and retrieve the Order Number, Order Total, and Payment Date from the downloaded file.
The first column has the little green ribbon at the top left corner also.
The last three columns is the output I wish to achieve
Company NumberInvoice NumberOrder NumberOrder TotalPayment Date
1111111111ABC12381900901206603/14/2024
2222222222111222000819009000010,000.00


Order Number:
To retrieve the Order Number, I use FILTER and UNIQUE. It retrieves it successfully when the invoice number in my spreadsheet has text formatting e.g. ABC123
But it doesn't work when the invoice number in my spreadsheet has number formatting because the invoice numbers in the downloaded file does not have number formatting. How can I make the formula work for both text and numbers.

Also, how can I retrieve the correct order number when the correct invoice number is "ABC123" but it was incorrectly booked as "ABC123 y"

Order Total:
I use two SUMIFS to add the Order Tax and Order Subtotal columns together.
Is there a more efficient way to add these? Or is this okay to use.

Payment Date:
How can I retrieve the payment date for invoice ABC123? The date does not necessarily show in all rows in the extracted data
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Order Number:
To retrieve the Order Number, I use FILTER and UNIQUE. It retrieves it successfully when the invoice number in my spreadsheet has text formatting e.g. ABC123
But it doesn't work when the invoice number in my spreadsheet has number formatting because the invoice numbers in the downloaded file does not have number formatting. How can I make the formula work for both text and numbers.
Format the field "Invoice Number" in the second sheet as text.

Order Number:
Also, how can I retrieve the correct order number when the correct invoice number is "ABC123" but it was incorrectly booked as "ABC123 y"
Try using wildcard character *.

Order Total:
I use two SUMIFS to add the Order Tax and Order Subtotal columns together.
Is there a more efficient way to add these? Or is this okay to use.
SUMIFS() is okay.

Payment Date:
How can I retrieve the payment date for invoice ABC123? The date does not necessarily show in all rows in the extracted data
Try MAX()/MIN().
 
Upvote 0
Is it true that when you filter using Company Number and Invoice Number that you will obtain multiple entries from the Daily sheet, and...
  1. all of those entries will have the same Order Number, and
  2. the Payment Date for that subset of entries will either be blank or share the same date?
 
Last edited:
Upvote 0
Here is one approach: The initial Daily data range is defined as variable "data", and assumed column order is as shown in your example. The Company Number (cnum) and Invoice Number (inum) columns are assigned to variables for convenient referencing. The main data range is filtered and assigned to variable "fd". The filtering uses an ISNUMBER(SEARCH method for determining if the Invoice Number matches the "inum" array. This method is a text-based method, so whether numbers or text are in "inum", the function treats them as text, as it does your input Invoice Number in column B of your own worksheet. Be careful, however, as it matches only the text string, so if you enter an invoice of ABC123 in B2, this will find matches for "ABC123 y" or "xABC123" or 1ABC123z"..., so you will need to be reasonably sure that these types of matches are acceptable. The filtering uses an exact match for Company Number, assumed to be the same data type between both the reference data table and your worksheet. Then the "fd" extracted data is split up into three arrays:
  1. "onum" is the Order Number, and assuming all Order Numbers are shown for every entry in the main data table, we TAKE just the first one in the "fd" data;
  2. "ototal" is the sum of the Order Tax and Order Subtotal for the extracted "fd" data; and
  3. "pmtdt" is the maximum date of the Payment Date in the "fd" data. Because it is conceivable that no date may be shown at all, a follow-up formula "pdt" specifies whether to show "none" for the date or the actual payment date.
Finally, these results are stacked together so that all three results will spill. In the event that the original "fd" FILTER does not find any entries that match the Company Number and Invoice Number inputs, an error will be produced, and we trap this error in the final output by wrapping the results in an IFERROR function that displays "not found" in the Order Number column.

MrExcel_20240315.xlsx
ABCDEFGH
1Company NumberInvoice NumberOrder NumberOrder DateOrder TaxOrder SubtotalCurrencyPayment Date
21111111111ABC123 y81900901204536310100AUD
31111111111ABC123 y81900901204536350500AUD
41111111111ABC123 y81900901204536300AUD3/14/2024
51111111111ABC123 y81900901204536300AUD3/14/2024
6
72222222222111222000819009000045292010000AUD
Daily

MrExcel_20240315.xlsx
ABCDE
1Company NumberInvoice NumberOrder NumberOrder TotalPayment Date
21111111111ABC1238190090120660.003/14/2024
32222222222111222000819009000010,000.00none
4333not found
MyOwn
Cell Formulas
RangeFormula
C4,C2:E3C2=LET(data,Daily!$A$2:$H$7,cnum,CHOOSECOLS(data,1),inum,CHOOSECOLS(data,2), fd,FILTER(data,(cnum=A2)*ISNUMBER(SEARCH(B2,inum))), onum,TAKE(CHOOSECOLS(fd,3),1), ototal,SUM(CHOOSECOLS(fd,5,6)), pmtdt,MAX(CHOOSECOLS(fd,8)), pdt,IF(pmtdt=0,"none",pmtdt), IFERROR(HSTACK(onum,ototal,pdt),"not found"))
Dynamic array formulas.
 
Upvote 1
Solution
A variation

Book1
ABCDEFGH
1Company NumberInvoice NumberOrder NumberOrder DateOrder TaxOrder SubtotalCurrencyPayment Date
21111111111ABC123 y81900901204536310100AUD
31111111111ABC123 y81900901204536350500AUD
41111111111ABC123 y81900901204536300AUD45365
51111111111ABC123 y81900901204536300AUD45365
6
72222222222111222000819009000045292010000AUD
8
9
10
11
12Company NumberInvoice NumberOrder NumberOrder TotalPayment Date
131111111111ABC123819009012066045365
142222222222111222000819009000010000none
1533not found
Sheet1
Cell Formulas
RangeFormula
C15,C13:E14C13=LET(c,CHOOSECOLS($A$2:$H$7,3,5,6,8),z,FILTER(c,ISNUMBER(SEARCH(B13,$B$2:$B$7))),IFERROR(HSTACK(MAX(INDEX(z,,1)),SUM(TAKE(DROP(z,,1),,2)),IFERROR(1/(1/(MAX(TAKE(z,,-1)))),"none")),"not found"))
Dynamic array formulas.
 
Upvote 1
Is it true that when you filter using Company Number and Invoice Number that you will obtain multiple entries from the Daily sheet, and...
  1. all of those entries will have the same Order Number, and
  2. the Payment Date for that subset of entries will either be blank or share the same date?
Hi Kirk, thank you very much for your help, I appreciate it 🙏
  1. all of those entries will have the same Order Number --> Some invoice numbers will have multiple/different Order Numbers
  2. the Payment Date for that subset of entries will either be blank or share the same date? Yes, correct. The Max formula will work great.

For invoice numbers which have multiple Order Numbers, what would you change in your formula?
 
Upvote 0
I wanted to caution you about something with the ISNUMBER(SEARCH feature. It can cause false positives when the 1st argument of SEARCH (find_text) is blank...then it returns a match nearly everywhere. I realized this when I tried reworking the formula a bit to use the Payment Date method shown by @JEC...the double reciprocal is a clever way to force an error when no date is present, yet return the date when one is. That formula too would be vulnerable to this same issue. If you'll never need to worry about a blank Invoice Number in your worksheet, then this isn't an issue. If you might have a blank, then another error trap is probably needed. Also, I must not have read the initial problem clearly, as I also included Company Name in the filter. That may not be an issue either, as the Company Name and Invoice Number may always be a 1:1 relationship. But if an invoice number is associated with more than one company, then that is an issue.
To clean up the formula, and condense it further, and borrowing the payment date idea from @JEC something like this will handle the blank Invoice Number...which intentionally throws an error result that is later converted to "not found":
MrExcel_20240315.xlsx
ABCDE
1Company NumberInvoice NumberOrder NumberOrder TotalPayment Date
21111111111ABC1238190090120660.003/14/2024
32222222222111222000819009000010,000.00none
4333not found
MyOwnWkSht
Cell Formulas
RangeFormula
C4,C2:E3C2=LET(d,Daily!$A$2:$H$7,f,IF(B2="",#N/A,FILTER(d,ISNUMBER(SEARCH(B2,INDEX(d,,2))))),IFERROR(HSTACK(INDEX(f,1,3),SUM(CHOOSECOLS(f,5,6)),IFERROR(1/(1/MAX(TAKE(f,,-1))),"none")),"not found"))
Dynamic array formulas.

For invoice numbers which have multiple Order Numbers, what would you change in your formula?
What do you want to do with multiple order numbers? Right now, you enter just the Invoice Number and extract all data that matches it. Do you want subtotals for each of the unique order numbers in that subset? Or are you saying that you'd like to initially filter on both the Invoice Number and an inputted Order Number?
 
Last edited:
Upvote 0
Daily
Company NumberInvoice NumberOrder NumberOrder TaxOrder SubtotalPayment Date
1111111111DEF789777777777722212/12/2024
1111111111ABC123 z888888888850500
1111111111ABC123 y999999999910010003/14/2024
2222222222ZZZZZZAAAAAAAAA110
MyOwn(start)
Company NumberInvoice NumberOrder NumberOrder TotalPayment Date
1111111111DEF789
1111111111ABC123
2222222222ZZZZZZ
MyOwn(end)
Company NumberInvoice NumberCount of Order NumbersOrder NumberOrder TotalPayment Date
1111111111DEF789177777777772412/12/2024
1111111111ABC12328888888888550
999999999911003/14/2024
2222222222ZZZZZZ1AAAAAAAAA11


Yes, the same output for each order number.

Since some invoice numbers can have multiple order numbers, I'm not sure how best to achieve the desired output.
Where there are multiple order numbers, since the results will spill but cannot spill if there is data in the rows below, perhaps I should insert a new column notifying me of the count of order numbers? So I can manually insert new rows for the formula to spill? Not sure though

Noted on the revised formula regarding the ISNUMBER feature, thank you.
 
Upvote 0
I agree about the spill issue. There are a few options. You could do a count as you've suggested, which tells you to dig deeper. You could spill sets of results horizontally...a set for each order number. Or you could abandon reporting on the table structure defined by your inputted Invoice Numbers and create an entirely new results table that spills down, shifting lower result blocks so that that don't interfere with those above...I think that's doable, but more complicated. Do you have a preference?

Tell me about the order 888... result line. The Payment Date is blank? So that's an extension of the same idea. The filtered data set would be based on a unique order number and a, perhaps, common invoice number. ...and the order total and payment date would be reflect only those items.
 
Upvote 0
I agree about the spill issue. There are a few options. You could do a count as you've suggested, which tells you to dig deeper. You could spill sets of results horizontally...a set for each order number. Or you could abandon reporting on the table structure defined by your inputted Invoice Numbers and create an entirely new results table that spills down, shifting lower result blocks so that that don't interfere with those above...I think that's doable, but more complicated. Do you have a preference?

Tell me about the order 888... result line. The Payment Date is blank? So that's an extension of the same idea. The filtered data set would be based on a unique order number and a, perhaps, common invoice number. ...and the order total and payment date would be reflect only those items.

I don't have a preference on the spill ideas. I am happy to apply any method.

Regarding invoice number ABC123.
Our supplier sends us this invoice and I would enter the invoice into the accounting software. We can book the whole amount of the invoice once (i.e. 1 x Order Number for 1 x invoice)
Or we can book half of it now, half of it later (2 x Order Numbers for 1 x invoice).

And that's why the payment date exists for one order number but not another. Because they can be paid at separate times.
 
Upvote 0

Forum statistics

Threads
1,215,086
Messages
6,123,043
Members
449,092
Latest member
ikke

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