Help with FILTER function

jdellasala

Well-known Member
Joined
Dec 11, 2020
Messages
755
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
  3. Web
I posted an item regarding Mr.E's Excel Formula To Extract Country From Phone Number - 2370 which I loved here today. I used a 365 formula to lookup Country Codes like this:
CountryCodeLookups.xlsx
AB
1+447594361587United Kingdom
2+41769482539Switzerland
3+35056369249Gibraltar
Sheet1
Cell Formulas
RangeFormula
B1:B3B1=LET(Ph,SUBSTITUTE(A1,"+",""), IFNA(XLOOKUP(LEFT(Ph,6)+0,CountryCodes[Code],CountryCodes[Country]), IFNA(XLOOKUP(LEFT(Ph,5)+0,CountryCodes[Code],CountryCodes[Country]), IFNA(XLOOKUP(LEFT(Ph,4)+0,CountryCodes[Code],CountryCodes[Country]), IFNA(XLOOKUP(LEFT(Ph,3)+0,CountryCodes[Code],CountryCodes[Country]), IFNA(XLOOKUP(LEFT(Ph,2)+0,CountryCodes[Code],CountryCodes[Country]), IFNA(XLOOKUP(LEFT(Ph,2)+0,CountryCodes[Code],CountryCodes[Country]), IFNA(XLOOKUP(LEFT(Ph,1)+0,CountryCodes[Code],CountryCodes[Country]), "#ERROR!"))))))))
which references a Table of codes.
Anyway, the formula works fine, but I thought I might be able to streamline it a bit more using SEQUENCE function like this:
CountryCodeLookups.xlsx
DE
3+447594361587 
4
5
6
7United Kingdom
Sheet1
Cell Formulas
RangeFormula
E3:E8E3=LET(Ph,SUBSTITUTE(D3,"+",""),IFNA(XLOOKUP(LEFT(Ph,SEQUENCE(6,,6,-1))+0,CountryCodes[Code],CountryCodes[Country]),""))
Dynamic array formulas.

I get the answer, but I need to filter it to get only the item with a value. I tried this:
CountryCodeLookups.xlsx
DE
3+447594361587#VALUE!
Sheet1
Cell Formulas
RangeFormula
E3E3=LET(Ph,SUBSTITUTE(D3,"+",""),FILTER(IFNA(XLOOKUP(LEFT(Ph,SEQUENCE(6,,6,-1))+0,CountryCodes[Code],CountryCodes[Country]),""),"<>"))

but obviously either FILTER won't work or I've got it wrong. Any help?
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
You could use LOOKUP:

Excel Formula:
=LET(Ph,SUBSTITUTE(D3,"+",""),LOOKUP(REPT("Z",255),XLOOKUP(LEFT(Ph,SEQUENCE(6,,6,-1))+0,CountryCodes[Code],CountryCodes[Country])))

Your FILTER syntax appears to be confused with COUNTIF. FILTER requires an array of criteria.
 
Upvote 0
Solution
You could use LOOKUP:

Excel Formula:
=LET(Ph,SUBSTITUTE(D3,"+",""),LOOKUP(REPT("Z",255),XLOOKUP(LEFT(Ph,SEQUENCE(6,,6,-1))+0,CountryCodes[Code],CountryCodes[Country])))

Your FILTER syntax appears to be confused with COUNTIF. FILTER requires an array of criteria.
I don't follow. This still results in a #VALUE! error:
Excel Formula:
=LET(Ph,SUBSTITUTE(D3,"+",""),FILTER(IFNA(XLOOKUP(LEFT(Ph,SEQUENCE(6,,6,-1))+0,CountryCodes[Code],CountryCodes[Country]),""),"="&CountryCodes[Country]))
The array FILTER is looking at are the 6 results of the XLOOKUP. Don't follow where COUNTIF would fit in.
I'm trying to condense the 6 XLOOKUPS in the beginning into one XLOOKUP, but don't want all 6 results. Need a DROPIFS function!
 
Upvote 0
It works fine for me.

I wasn't saying you should use COUNTIF. I was saying that the syntax you are using for your FILTER criterion is what you would use for COUNTIF, not what you'd use for FILTER. FILTER needs an array of True/False values, not a single value.
 
Upvote 0
It works fine for me.

I wasn't saying you should use COUNTIF. I was saying that the syntax you are using for your FILTER criterion is what you would use for COUNTIF, not what you'd use for FILTER. FILTER needs an array of True/False values, not a single value.
I understood what you meant, but it didn't make sense. I was looking for help, not obscure hints.
No check for you!
 
Upvote 0
I gave you a working formula and explained why your syntax was wrong.

I'll leave you be.
 
Upvote 0
I gave you a working formula and explained why your syntax was wrong.

I'll leave you be.
OMG! My bad!!! I just moved and had the cable guy here and totally missed the formula in your first post. I couldn't understand why you hadn't posted a solution. I should have known better.
That said, I'm not sure how or why it works, but I'll investigate further.
THANK YOU!
 
Upvote 0

Forum statistics

Threads
1,223,230
Messages
6,170,883
Members
452,364
Latest member
springate

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