Sorting occurrences of Postal Code in column / Sorting by occurrence high to low

jsmith70

New Member
Joined
Jul 7, 2019
Messages
12
Office Version
  1. 365
Platform
  1. Windows
I was working on something a bit more convoluted earlier, where user @etaf really took the time to explain/give guidance, which i really appreciated - but I pivoted and will be using something a bit simpler. I am curious about the following:

I would like to utilize Column L (abbreviated) and have it sort how many times each occurs - then create a 2 column table where it has the abbreviated in column A / times it occurred in column B. So if V2N occurred 5 times I just want to see V2N | 5 - not five rows of V2N. I will subsequently want to sort this data out into 4 separate provincial tables as well so we can isolate province down from all areas. I have fumbled with some formulas to get pieces of what I want but do not know how to combine it all into one.


Book1.xlsx
KLMN
1Postal CodeAbbreviatedProvCity
2S7M4J5S7MSKSaskatoon
3V4E2V1V4EBCNorth Delta
4R3R2N2R3RMBWinnipeg
5V2C2R3V2CBCKamloops
6T3M0G4T3MABCalgary S/Cranston
7V2N2T4V2NBCPrince George College Heights
8V8Z7H3V8ZBCVictoria Royal Oak/Cordova Bay
9T6J4L3T6JABEdmonton
10R3l0X5R3lMBWinnipeg
11S9A2X3S9ASKNorth Battleford
12S7H4B1S7HSKSaskatoon
13T7X3Y3T7XABSpruce Grove
14T9V3B4T9VABLloydminster
15T2K3G2T2KABCalgary
16T6R2K4T6RABEdmonton
17S7H5E1S7HSKSaskatoon
18V2B3L8V2BBCKamloops
19V5W1A4V5WBCVancouver
20T2Y2X5T2YABCalgary S
21T0M0K0T0MABAirdrie East/Sundre/Crossfields
22V1H2B8V1HBCVernon North
23S7K2K2S7KSKSaskatoon
24T1H1A4T1HABLethbridge North/Coaldale/Taber
25V9W1M5V9WBCCampbell River
26S0K2A0S0KSKMartensville
27V9N0E6V9NBCParksville
28V9N9L2V9NBCParksville
29V2C 0B4V2CBCKamloops
30V8Z 4C6V8ZBCVictoria Royal Oak/Cordova Bay
31T1H 2P7T1HABLethbridge North/Coaldale/Taber
32T1K6R4T1KABLethbridge South
33V7P1H8V7PBCNorth Vancouver
34S0J0J0S0JSKChoiceland
35V1R3C6V1RBCTrail
36V1R 3C8V1RBCTrail
37T1X0N6T1XABChestermere
38V1B 9V4V1BBCVernon South/Armstrong/Lumby/Winfield
39V2N0G9V2NBCPrince George College Heights
40V9C3X1V9CBCVictoria/Colwood
41S7N1Y1S7NSKSaskatoon
42T2S0A6T2SABCalgary S Central
43V5A4S1V5ABCBurnaby
44T8L 2J4T8LABFort Saskatchewan
45V3S 0X6V3SBCSurrey
46V7Z0L1V7ZBCVancouver
47R0C0Z0R0CMBStonewall/South Interlake
48R3T4M8R3TMBWinnipeg
49T3K0K1T3KABCalgary NW
50T2M6Y8T2MABCalgary N
51T6C2J6T6CABEdmonton
52V3R7E7V3RBCSurrey
53R2R 2J7R2RMBWinnipeg
54R3T2G2R3TMBWinnipeg
55T5T6C6T5TABEdmonton
56V9B2J2V9BBCVictoria W Highlands/Colwood/Langford/View Royal
57V3V7T2V3VBCSurrey
58T2T0R1T2TABCalgary S Central
59T2C3P4T2CABCalgary E
60V9X1E7V9XBCNanaimo South/Ladysmith
61S7H5S7S7HSKSaskatoon
62S4V3L3S4VSKRegina East
63T2Y3G3T2YABCalgary S
64T6T1l1T6TABEdmonton
65S7N 4M2S7NSKSaskatoon
66S4S4F4S4SSKRegina South
67V3T2N3V3TBCSurrey
68V8T1X9V8TBCVictoria/Esquimalt
69R3X0C6R3XMBWinnipeg
70V3N1L9V3NBCBurnaby
71V3B4P3V3BBCPort Coquitlam
72T9E0T8T9EABLeduc
73R2W3l5R2WMBWinnipeg
74V4A4X9V4ABCSurrey
75V3E0T4V3EBCCoquitlam
76V0R2P4V0RBCCowichan Valley
77T7X3V3T7XABSpruce Grove
78T4B1S6T4BABAirdrie West
79R3R0W7R3RMBWinnipeg
80T5Z2Z8T5ZABEdmonton
81R3R0W7R3RMBWinnipeg
82V5P3A9V5PBCVancouver
83V1W3H4V1WBCKelowna
84V2N0C2V2NBCPrince George College Heights
85V1Z4E1V1ZBCWest Kelowna/Peachland
86V5R4C9V5RBCVancouver
87V4P1B8V4PBCSurrey
88V1V3G1V1VBCKelowna
89V3V2B8V3VBCSurrey
90T7X3S3T7XABSpruce Grove
91T5Y3J1T5YABEdmonton
92T3H5Z1T3HABCalgary SW
93T3G6A4T3GABCalgary NW
94V3E0E9V3EBCCoquitlam
95V4L2J7V4LBCDelta
96T3H4Y5T3HABCalgary SW
97T5Y2X5T5YABEdmonton
98R2C3N5R2CMBWinnipeg
99V6H1Z4V6HBCVancouver
100T5R2W1T5RABEdmonton
101T6R0B1T6RABEdmonton
102T6K0L2T6KABEdmonton
103T3J3A3T3JABCalgary
104R3T3X1R3TMBWinnipeg
105R2M2V4R2MMBWinnipeg/St Vital
106T3K5J2T3KABCalgary NW
107V7N1L8V7NBCNorth Vancouver
108T5X5P9T5XABEdmonton
109V9L0A6V9LBCDuncan
110R3N0R6R3NMBWinnipeg
111T3Z1E1T3ZABBragg Creek/Redwood Meadows/Springbank
112T3E5A4T3EABCalgary SW
113R3P1A4R3PMBWinnipeg
114V7T2L4V7TBCWest Vancouver
115R3Y2B9R3YMBWinnipeg
116S6V1M5S6VSKPrince Albert
117T3G4R5T3GABCalgary NW
118V2T5B3V2TBCAbbotsford
119R0A0V2R0AMBSteinbach/Southern Communities
120T2W 3V5T2WABCalgary SW
121S0H 3G0S0HSKMoose Jaw
122V7L1P5V7LBCNorth Vancouver
123T2B2E4T2BABCalgary E
124T2V2A2T2VABCalgary SE
125T3M0L5T3MABCalgary S/Cranston
126R2P1Y7R2PMBWinnipeg
127V3T 0E7V3TBCSurrey
128T3M1V1T3MABCalgary S/Cranston
129T5P3M8T5PABEdmonton
130V3H 0A6V3HBCPort Moody
131T2J1M1T2JABCalgary SE
132T7S0C8T7SABWhitecourt
133T3H 4X6T3HABCalgary SW
134V8B 2A1V8BBCSquamish/Lions Bay
135V1W5K4V1WBCKelowna
136V1E1K5V1EBCSalmon Arm
137T2E 1L8T2EABCalgary
138V7S0A4V7SBCWest Vancouver
139V5R 1T5V5RBCVancouver
140V0R1R0V0RBCCowichan Valley
141R7A0W4R7AMBBrandon 2
142R0M1P0R0MMBDauphin
143R3G3C5R3GMBWinnipeg
144V9T4S4V9TBCNanaimo North/Lantzville
145v2n5k6v2nBCPrince George College Heights
Leads
Cell Formulas
RangeFormula
L2:L145L2=LEFT([@[Postal Code]],3)
M2:M145M2=IF(LEFT(L2,1)="R","MB",IF(LEFT(L2,1)="S","SK",IF(LEFT(L2,1)="T","AB",IF(LEFT(L2,1)="V","BC",""))))
N2:N145N2=VLOOKUP(L2, FranchiseeBaseline!$A$2:$F$500, 6)
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
How about
Excel Formula:
=LET(u,UNIQUE(L2:L145),SORT(HSTACK(u,COUNTIFS(L:L,u)),2,-1))
 
Upvote 0
Solution
How about
Excel Formula:
=LET(u,UNIQUE(L2:L145),SORT(HSTACK(u,COUNTIFS(L:L,u)),2,-1))
well that was quick - and amazing thank you - yes this worked perfectly. i really appreciate it and will look into what you gave me so i can understand (rather than just taking).

now before i start playing with this - if i wanted to add a condition to split out by province can this formula accommodate this? i would presume the easiest would be simply adding the first letter (V, T etc..) as the condition as they are unique to each province rather than identifying a separate 'provincial' column altogether.
 
Upvote 0
Two alternative options
New Excel formula GroupBy
Excel Formula:
=GROUPBY(Table1[[#All],[Abbreviated]],Table1[[#All],[Abbreviated]],COUNTA)

Power Query
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Grouped Rows" = Table.Group(Source, {"Abbreviated"}, {{"Count", each Table.RowCount(_), Int64.Type}})
in
    #"Grouped Rows"
 
Upvote 0
if i wanted to add a condition to split out by province
How about
Excel Formula:
=LET(u,UNIQUE(L2:L145),s,SORT(HSTACK(u,COUNTIFS(L:L,u)),2,-1),FILTER(s,LEFT(INDEX(s,,1))="V"))
 
Upvote 0
Thank you everyone for suggestions/help on this, it is really appreciated. sorry for the gap in time replying to this - some of that life stuff got in the way recently :)..

@Fluff - can more variables be added to that formula. I am totally out of my depth here but i'm curious about a couple things. with the above example spreadsheet - if there was a column O tracking dollars of booked jobs (so Row 2 would be S7M 4J5 / S7M / SK / Saskatoon / $5,000) can the following examples be done with the current formula?

1. tallying up instances each postal code shows up as it is doing - then adding up the subsequent column O values to match?
or
2. tallying up dollar amounts high to low with the abbreviated postal beside it.

does that make sense how i'm asking?

or:
V2N had 3 jobs @ 5,000 each for $15,000
V8R had 2 jobs @ 5,000 each for $10,000
V9B had 1 job @ 5,000 for $5,000

does it have the ability to sort by highest to lowest dollar figure and show the matching abbreviated postal code beside it?

so visually - is that doable within this formula, or is this a different one i'm looking for

Jobs Total $ Postal Code Sold Leads
$15,000 V2N 3
$10,000 V8R 2
$5,000 V9B 1
 
Upvote 0
How about
Excel Formula:
=LET(u,UNIQUE(L2:L145),SORT(HSTACK(u,COUNTIFS(L:L,u),SUMIFS(O:O,L:L,u)),3,-1))
 
Upvote 0

Forum statistics

Threads
1,223,881
Messages
6,175,159
Members
452,615
Latest member
bogeys2birdies

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