2 Replies Latest reply on Apr 2, 2013 4:40 AM by Sheron Madhushanka

    Length Function on Postcodes

    Sheron Madhushanka

      Hi,

       

      I'm trying to separate first two digits of an Italian postcodes using length function. Although tableau recognised this as a postcode, everytime I use Length() it wants me to change it to a string.

      But if I convert to string it looses first zeros's from the 5 digit postcode?

       

      Is there a quick fix for this?

       

      thanks

      Sheron

        • 1. Re: Length Function on Postcodes
          Andrew Ball

          Hi Sheron,

           

          The Length() function requires a string, so you do need the postcodes to be strings to extract the first two characters using this method. However, to have leading zeros, I would have expected the field to be a string anyway. Otherwise, there will be no leading zeros.

          Can you clarify some details about where the data is coming from, and what format?

           

          If, for example, the postcode is stored as a number, it will not have leading zeros, so you would need to do something like:

          LEFT(LEFT("00000",5-LEN(STR([Postcode])))+STR([Postcode]),2)

           

          This will get the first 2 digits from a 5 digit postcode that is stored as a number.

           

          Hope that helps. If not, some clarification on your exact circumstances would be helpful.

           

          Andrew

          1 of 1 people found this helpful
          • 2. Re: Length Function on Postcodes
            Sheron Madhushanka

            Hi Andrew,

             

            Yea it was treating the field as a number and your function worked perfectly

             

            Thanks

            Sheron