Kevin Cheesman Posted September 22, 2009 Posted September 22, 2009 I need our postcode to display in the correct order. I've broken the first part down into 2 fields so I can sort on the text and numbers, but I need to sort the second part of the postcode too. The UK postcode format is usually TTNN TNN, however then first part can consist of just one letter or just one number. There is always a space in between the two parts.
Kevin Cheesman Posted September 22, 2009 Author Posted September 22, 2009 What I was thinking of doing was breaking the poscode field into 4 different calculated fields. So the text field, Poscode holding BR23 7TB would become... BR (text field) 23 (numeric field) 7 (numeric field) TB (text field) I could then sort on these fields to ensure the actual postcode field in sorted correctly.
Kevin Cheesman Posted September 22, 2009 Author Posted September 22, 2009 You haven't answered my question. The correct order for BR23 3TU would be.. BR - ascending 23 - ascending 3 - ascending TU - ascending This would ensure that BR1 is not followed by BR12 but BR2 etc. and the same for the second part of the postcode.
comment Posted September 22, 2009 Posted September 22, 2009 (edited) OK, then wouldn't it be sufficient to insert a zero after the first one or two alpha characters when they are followed by a single digit? That is "BR12 3TU" would remain unchanged, while "BR1 3TU" would be turned into "BR01 3TU". Edited September 22, 2009 by Guest
Kevin Cheesman Posted September 22, 2009 Author Posted September 22, 2009 Yes, not a problem, but what I looking for is a calculation to scan the existing postcodes and break them down.
comment Posted September 22, 2009 Posted September 22, 2009 I am afraid I don't follow you. What would be the purpose of breaking it into four calculation fields, when it can be done by a single one? Not to mention that sorting by one field is more efficient than by four separate ones.
Kevin Cheesman Posted September 22, 2009 Author Posted September 22, 2009 ok, so how do I sort on just part of a field and how do I sort the numbers when they are currently text?
David Jondreau Posted September 22, 2009 Posted September 22, 2009 (edited) I presume what comment is getting at is that you don't need 4 additional fields. You only need one, Post Code Sort. That field will have the calculation that will return the post code in a sortable format. It's not clear how a single letter in the first part of the code should sort, but I'd assume it should sort above any double letter. B23 sorts before BA11? Let([ PostCode = Upper(table::field); first = LeftWords(PostCode;1); second = Rightwords(PostCode;1); lets = filter(first;"ABCDEFGHIJKLMNOPQRSTUVWXYZ"); lets = Left(lets & 0;2); nums = filter(first;"0123456789"); nums = Right(0& nums;2); result = lets & nums & second ]; result ) PS: Got distracted and posted later than I intended...This was in response to post #341074. Edited September 22, 2009 by Guest
Kevin Cheesman Posted September 23, 2009 Author Posted September 23, 2009 Added this calc field. It concatenates the postcode but they do not display in the correct numerical order when you sort on this field.
comment Posted September 23, 2009 Posted September 23, 2009 Could you provide a specific example? Like, these codes sort in this order, when they should sort in this order?
Kevin Cheesman Posted September 23, 2009 Author Posted September 23, 2009 Sort order is back up the thread. The correct order for BR23 3TU would be.. BR - ascending 23 - ascending 3 - ascending TU - ascending This would ensure that BR1 is not followed by BR12 but BR2 etc. and the same for the second part of the postcode.
comment Posted September 23, 2009 Posted September 23, 2009 I believe DJ's calculation should provide that. If you're seeing something else, it may be due to incorrect implementation (make sure the result type is Text) or something that I am missing. If the latter, I will keep missing it unless you show it me.
Kevin Cheesman Posted September 23, 2009 Author Posted September 23, 2009 Oops! It was me. Yes, it does work. Thanks for all your help.
Recommended Posts
This topic is 5599 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now