+ Reply to Thread
Results 1 to 12 of 12

COUNTIF not calculating postcodes correctly

  1. #1
    Forum Contributor
    Join Date
    06-07-2018
    Location
    Newcastle Upon Tyne, England
    MS-Off Ver
    365
    Posts
    143

    COUNTIF not calculating postcodes correctly

    Hi,

    I am trying to use COUNTIF to count postcodes however, I am struggling to get this to work with some postcodes starting with the same character.

    Uploaded a desensitised sample for context and highlighted the error in red.

    Any help with the formula is much appreciated!

    Thanks
    Attached Files Attached Files

  2. #2
    Banned User!
    Join Date
    02-26-2020
    Location
    US
    MS-Off Ver
    2010
    Posts
    157

    Re: COUNTIF not calculating postcodes correctly

    Maybe try :

    Formula: copy to clipboard
    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    06-07-2018
    Location
    Newcastle Upon Tyne, England
    MS-Off Ver
    365
    Posts
    143

    Re: COUNTIF not calculating postcodes correctly

    My apologies - the sample was not as clear as it should have been. The postcodes column will be actual full postcodes (I used '...' to show there will be more characters).

    I have amended my sample and re-uploaded.

    Please note all postcodes in the sample are made up and not sensitive.
    Attached Files Attached Files

  4. #4
    Banned User!
    Join Date
    02-26-2020
    Location
    US
    MS-Off Ver
    2010
    Posts
    157

    Re: COUNTIF not calculating postcodes correctly

    There needs to be some consistency for your lookup. Maybe the first 2 characters would work then we can use LEFT in the formula.

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    Last edited by RChad; 03-25-2020 at 10:11 AM.

  5. #5
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: COUNTIF not calculating postcodes correctly

    Please try

    for 1 digit number after District Code
    =COUNTIF(Table1,C2&"? *")

    for 1-2 digit number after District Code
    =SUMPRODUCT(--(LEFT(Table1,MMULT(--ISNUMBER(-MID(Table1,{2,3},1)),{1;2}))=C2))
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    06-07-2018
    Location
    Newcastle Upon Tyne, England
    MS-Off Ver
    365
    Posts
    143

    Re: COUNTIF not calculating postcodes correctly

    Thanks for your responses, much appreciated!

    My only concern is that on my live workbook, postcodes are constantly added to the document. Therefore I am looking for one formula to cover the full list, regardless of one or two digits, if that makes sense?

    I have a full list of all district codes and that won't change, I will simply adding postcodes and hope the one formula can do the equation?

  7. #7
    Forum Expert Bob Phillips's Avatar
    Join Date
    09-03-2005
    Location
    Wessex
    MS-Off Ver
    Office 2003, 2010, 2013, 2016, 365
    Posts
    3,284

    Re: COUNTIF not calculating postcodes correctly

    Bo_Ry's formula does exactly that, have you tried it?

  8. #8
    Forum Contributor
    Join Date
    06-07-2018
    Location
    Newcastle Upon Tyne, England
    MS-Off Ver
    365
    Posts
    143

    Re: COUNTIF not calculating postcodes correctly

    I have added two additional postcodes to the list and highlighted in green. Their district should be 'L' and 'B' however they are not added to the total count.

    I do apologise if I'm not explaining myself very well, I do appreciate your time.
    Attached Files Attached Files

  9. #9
    Banned User!
    Join Date
    02-26-2020
    Location
    US
    MS-Off Ver
    2010
    Posts
    157

    Re: COUNTIF not calculating postcodes correctly

    You are making this more complicated than it needs to be I am opting out.

  10. #10
    Forum Contributor
    Join Date
    06-07-2018
    Location
    Newcastle Upon Tyne, England
    MS-Off Ver
    365
    Posts
    143

    Re: COUNTIF not calculating postcodes correctly

    I can't help that some district postcodes have one number following and others have two. That's why I'm scratching my head. I'm not an advanced user of Excel, so if I'm making it more difficult than needed, it's certainly not intentional. None the less, appreciate your input.

  11. #11
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,211

    Re: COUNTIF not calculating postcodes correctly

    Please try

    =SUMPRODUCT(--(LEFT(Table1,MOD(MMULT(--ISNUMBER(-MID(Table1,{2,3},1)),{1;2})-1,2)+1)=C2))


    Or
    =SUMPRODUCT(COUNTIF(Table1,C2&({0,1,2,3,4}+{0;5})&"*"))+COUNTIF(Table1,C2&" *")
    Attached Files Attached Files
    Last edited by Bo_Ry; 03-25-2020 at 01:29 PM.

  12. #12
    Forum Contributor
    Join Date
    06-07-2018
    Location
    Newcastle Upon Tyne, England
    MS-Off Ver
    365
    Posts
    143

    Re: COUNTIF not calculating postcodes correctly

    Absolutely spot on - thanks!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] COUNTIF formula based on first charactor or first two characters of Postcodes
    By davo3286 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 11-10-2022, 10:19 AM
  2. Calculating Google Maps Distances Using Postcodes
    By smart_as in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 05-14-2021, 03:08 PM
  3. Replies: 2
    Last Post: 06-03-2017, 04:49 PM
  4. Formula not calculating correctly
    By mgfuentes in forum Excel Formulas & Functions
    Replies: 10
    Last Post: 11-09-2012, 01:21 PM
  5. UK Postcodes which sort correctly?
    By diceman in forum Excel General
    Replies: 1
    Last Post: 11-26-2007, 08:08 PM
  6. Date Not calculating correctly
    By vbehler in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-18-2007, 05:01 PM
  7. [SOLVED] Macro not calculating correctly
    By Ozgur Pars in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-17-2006, 10:55 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1