+ Reply to Thread
Results 1 to 20 of 20

Return count of Postal Code based unique value

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-22-2005
    MS-Off Ver
    Office 365
    Posts
    342

    Return count of Postal Code based unique value

    Hey Excel Pro's

    Excel 2010

    In column A I have a list of account numbers.

    In column B I have a list of Postal codes.

    Account numbers could repeat in column A and because of this the postal code could repeat in column B. But a different account could have the same postal code as another account.

    I need to count the number of times a postal code shows up based on unique account number.
    Attached Files Attached Files
    Last edited by SVTF; 05-30-2017 at 10:06 PM.

  2. #2
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Return count of Postal Code based unique value

    You can try with Pivot Table:
    Attached Files Attached Files

  3. #3
    Forum Contributor
    Join Date
    08-22-2005
    MS-Off Ver
    Office 365
    Posts
    342

    Re: Return count of Postal Code based unique value

    Sorry should have mentioned excel 2010.

    Piviot table returns the number of times the postal code actually shows up.

    You must have used 2013+?

    Did not think you could do that in 2010?
    Last edited by SVTF; 05-30-2017 at 10:34 PM.

  4. #4
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2405
    Posts
    13,417

    Re: Return count of Postal Code based unique value

    This is a formula way.

    =SUMPRODUCT((D3=$B$2:$B$7)/COUNTIFS($A$2:$A$7,$A$2:$A$7))
    Dave

  5. #5
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Return count of Postal Code based unique value

    Ex 2k16
    And you are right on Ex2k10 you can't do that with PT because there is no Data Model
    so use Dave's solution

    edit: Update your profile about Office version. Will be easier for us and you for the future
    Last edited by sandy666; 05-30-2017 at 10:36 PM.

  6. #6
    Forum Contributor
    Join Date
    08-22-2005
    MS-Off Ver
    Office 365
    Posts
    342

    Re: Return count of Postal Code based unique value

    Thanks. Will test formula in morning on real data sheet.

    I assume I would just copy the formula down an empty column to right of data?

  7. #7
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2405
    Posts
    13,417

    Re: Return count of Postal Code based unique value

    Yes. I forgot to mention that part.

    If this formula is sluggish on the real data let me know. There are faster (but longer) formulas to do this.

  8. #8
    Forum Contributor
    Join Date
    08-22-2005
    MS-Off Ver
    Office 365
    Posts
    342

    Re: Return count of Postal Code based unique value

    FlameRetired

    Just noticed your formula points to D3.

    D3 is the sample output I was looking for. Real application would count postal codes in column B based of unique account number in A.

    Is there a tweak on that formula you could apply.

    Any chance you could plug into my test work book and attach of you have the time.

    Thanks.
    Last edited by SVTF; 05-30-2017 at 10:46 PM.

  9. #9
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2405
    Posts
    13,417

    Re: Return count of Postal Code based unique value

    I suspect I have over complicated this, but I can not seem to come up with a simpler formula.

    This uses an array formula in D3. If you aren’t familiar with array-entered formulas array enter means the formula must be committed from edit mode by simultaneously pressing and holding down Ctrl and Shift while hitting Enter.
    Formula: copy to clipboard
    =INDEX($B$2:$B$7,SMALL(IF(FREQUENCY(IF(FREQUENCY(MATCH($A$2:$A$7,$A$2:$A$7,0),ROW($A$2:$A$7)-MIN(ROW($A$2:$A$7))+1),MATCH($B$2:$B$7,$B$2:$B$7,0)),MATCH($B$2:$B$7,$B$2:$B$7,0)),ROW($A$2:$A$7)-MIN(ROW($A$2:$A$7))+1),ROWS($3:3)))

  10. #10
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2405
    Posts
    13,417

    Re: Return count of Postal Code based unique value

    The more I look at this the more it appears all you need is unique postal codes. Unless the same account number can have multiple postal codes this should simplify things a bit.

    Use a helper column. This formula would go in C2 and filled down.
    Formula: copy to clipboard
    =IF(B2="","",IF(COUNTIF($B$2:B2,B2)=1,ROWS($2:2),""))
    Then this formula goes in D3 and filled down until you get blanks.
    Formula: copy to clipboard
    =IFERROR(INDEX($B$2:$B$7,SMALL(C:C,ROWS($3:3))),"")

  11. #11
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2405
    Posts
    13,417

    Re: Return count of Postal Code based unique value

    You might also consider a pivot table. There are no calculations, and they are resource light.

  12. #12
    Forum Contributor
    Join Date
    08-22-2005
    MS-Off Ver
    Office 365
    Posts
    342

    Re: Return count of Postal Code based unique value

    Thanks. Will try these options today and report back.

  13. #13
    Forum Contributor
    Join Date
    08-22-2005
    MS-Off Ver
    Office 365
    Posts
    342

    Re: Return count of Postal Code based unique value

    Tested the helper formula does not return count of 2 & 1.

    In column c it shows value of 1 and 4?

    And in column D it shows the 1 of each postal code but because there is another account with the same postal code it should be duplicated again.

    Am i entering it wrong?
    Last edited by SVTF; 05-31-2017 at 05:43 AM.

  14. #14
    Forum Contributor
    Join Date
    08-22-2005
    MS-Off Ver
    Office 365
    Posts
    342

    Re: Return count of Postal Code based unique value

    Tested the index option only returns the postal code as 1 value but one of them should be repeated.

    The reason one should be repeated is because there is another account same postal code which can and will happen. And the postal code will be repeated for some accounts but only want to count once when that happens.

    End result I need to count postal code once per account number.

    Piviot table option...

    Excel 2013+ has data model option built in but we have 2010.

    Any other options to get this count in 2010?
    Last edited by SVTF; 05-31-2017 at 05:45 AM.

  15. #15
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Return count of Postal Code based unique value

    Maybe it will help:
    try
    1. copy postal values into another column
    2. select this range
    3. from the ribbon: DATA >>> DATA TOOLS >>> Remove Duplicates
    4. in the next column use formula:
    =SUM(IF(FREQUENCY(IF($A$2:$A$7<>"",MATCH($A$2:$A$7,$A$2:$A$7,0)),ROW($A$2:$A$7)-ROW($A$2)+1)>0,--($B$2:$B$7=H2))) with CSE & drag down

    OR

    (with your example)
    in D2: =IFERROR(INDEX($B$2:$B$7,MATCH(0,COUNTIF($D$1:D1,$B$2:$B$7),0)),"") array entered and drag down
    in E2: =IF(D2="","",SUM(IF(FREQUENCY(IF($A$2:$A$7<>"",MATCH($A$2:$A$7,$A$2:$A$7,0)),ROW($A$2:$A$7)-ROW($A$2)+1)>0,--($B$2:$B$7=D2)))) array entered and drag down

    CSE or array entered = ...confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer.
    Attached Files Attached Files
    Last edited by sandy666; 05-31-2017 at 07:15 AM.

  16. #16
    Forum Contributor
    Join Date
    08-22-2005
    MS-Off Ver
    Office 365
    Posts
    342

    Re: Return count of Postal Code based unique value

    sandy666,

    Looks like a version 1 above might work.

    When you remove duplicates... It makes that last shorter than the comparison list in B.

    What do I change in the formula to have it look at entire column of B.

    Would it be $B:$B ?

  17. #17
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Return count of Postal Code based unique value

    Using column range is not a good idea. Much better to use is defined range (it can be B2:B100000, but defined, if data exist in this range ).
    In this case if you try B:B you will get #N/A

    note: if you change B range to 10000 you should change all ranges to 10000 also
    Attached Files Attached Files
    Last edited by sandy666; 05-31-2017 at 09:15 AM.

  18. #18
    Forum Contributor
    Join Date
    08-22-2005
    MS-Off Ver
    Office 365
    Posts
    342

    Re: Return count of Postal Code based unique value

    Thanks.

    Does give results as asked.

    The only pitfall I see.

    There is already 30,000 lines or data and will triple that in next 3 months.

    Used the 2nd version you posted.

    Very taxing on the system.

    And with new data being added every month.

    Perhaps I need to convince my IT to upgrade to 2013 +

    Any other options that would not be as taxing on system?

    Thanks for the options you have provided thus far.

  19. #19
    Banned User!
    Join Date
    02-05-2015
    Location
    San Escobar
    MS-Off Ver
    any on PC except 365
    Posts
    12,168

    Re: Return count of Postal Code based unique value

    Perhaps I need to convince my IT to upgrade to 2013 +
    very good idea (or 365 plus - subscription)

    You've 1,048,576 rows to define ranges
    Last edited by sandy666; 05-31-2017 at 09:49 AM.

  20. #20
    Forum Moderator
    Join Date
    01-21-2014
    Location
    St. Joseph, Illinois U.S.A.
    MS-Off Ver
    Office 365 v 2405
    Posts
    13,417

    Re: Return count of Postal Code based unique value

    In previous attempts I seem to have had difficulty interpreting the mission.

    With that much data would you be willing to reconsider helper columns to lighten the load?

    In the attached column C returns postal codes where the pairings are unique. The formula is
    Formula: copy to clipboard
    =IF(COUNTIFS($A$2:A2,A2,$B$2:B2,B2)=1,B2,"")
    In helper column D my previous formula that returns row numbers for first occurrences of postal codes is
    Formula: copy to clipboard
    =IF(COUNTIF($B$2:B2,B2)=1,ROWS($2:2),"")


    Then final output of unique postal codes in column E would be
    Formula: copy to clipboard
    =IFERROR(INDEX($B$2:$B$35000,SMALL($D$2:$D$35000,ROWS($2:2))),"")
    and the counts in column F
    Formula: copy to clipboard
    =IF(E2="","",COUNTIF($C$2:$C$35000,E2))




    A
    B
    C
    D
    E
    F
    1
    account number
    postal code
    helper 1
    helper 2
    2
    12345
    E2J 4G3
    E2J 4G3
    1
    E2J 4G3
    2
    3
    12345
    E2J 4G3
    S2F 5T5
    1
    4
    12345
    E2J 4G3
    5
    98756
    S2F 5T5
    S2F 5T5
    4
    6
    98756
    S2F 5T5
    7
    65467
    E2J 4G3
    E2J 4G3

+ 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. Create unique # of worksheets based on list count with unique names
    By Groovicles in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-24-2016, 09:51 AM
  2. Postal Code List
    By KhalidIraq in forum Excel General
    Replies: 4
    Last Post: 01-09-2015, 10:39 AM
  3. Return Unique Items based on Count ans descending
    By jhall488 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-12-2014, 04:30 PM
  4. [SOLVED] Count unique entries based off unique criteria in another column
    By hambly in forum Excel Formulas & Functions
    Replies: 15
    Last Post: 06-11-2014, 03:33 PM
  5. Extract Postal code
    By terrysoper1973 in forum Excel General
    Replies: 10
    Last Post: 09-18-2011, 01:10 PM
  6. Postal Code Format
    By naive_nadeem in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-07-2011, 01:44 PM
  7. [SOLVED] Validation of Postal Code
    By Veronika in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-16-2005, 05:45 PM

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