+ Reply to Thread
Results 1 to 7 of 7

Power Query drops leading zeros when loading digits from column formatted as text

  1. #1
    Registered User
    Join Date
    07-05-2023
    Location
    Kzn, South Africa
    MS-Off Ver
    M365
    Posts
    3

    Unhappy Power Query drops leading zeros when loading digits from column formatted as text

    I am new to Power Query, but am already finding it a great help. However, I am coming unstuck in one area.
    I have a column consisting of South African ID numbers in my source data. The first 6 digits are date of birth (yymmdd), eg 850727. However, any IDs from 2000 onwards start with either 1 or 2 zeros, and these drop when loading the data.
    How do I work around this, please?

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,220

    Re: Power Query drops leading zeros when loading digits from column formatted as text

    Welcome to the forum.

    You will need to make sure that PQ reads the values as text, not numbers.

    There are instructions at the top of the page explaining how to attach your sample workbook (yellow banner: HOW TO ATTACH YOUR SAMPLE WORKBOOK). Screenshots are of little practical use as we cannot manipulate them.

    A good sample workbook has just 10-20 rows of representative data that has been desensitised. It also has expected results mocked up, worked examples where required, relevant cells highlighted and a few explanatory notes.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    07-05-2023
    Location
    Kzn, South Africa
    MS-Off Ver
    M365
    Posts
    3

    Unhappy Re: Power Query drops leading zeros when loading digits from column formatted as text

    The cells that drop leading zeros are highlighted in the attached file.
    Last edited by AliGW; 07-06-2023 at 04:38 AM. Reason: Redacted for legibility.

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,220

    Re: Power Query drops leading zeros when loading digits from column formatted as text

    When you import the table into PQ, you will see a step added automatically (changed type) - simply remove this step.

    To stop it happening, go here and scroll down to "How to stop the automatic Changed Type step?": https://exceloffthegrid.com/changed-...p-power-query/

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,761

    Re: Power Query drops leading zeros when loading digits from column formatted as text

    I suspect that you have PQ settings to automatically select data types. Change this to Never detect in the File-->Options and Settings-->Query Options-->Data Load
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  6. #6
    Registered User
    Join Date
    07-05-2023
    Location
    Kzn, South Africa
    MS-Off Ver
    M365
    Posts
    3

    Re: Power Query drops leading zeros when loading digits from column formatted as text

    Thank you both, I'll try that.

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,220

    Re: Power Query drops leading zeros when loading digits from column formatted as text

    Glad to have helped.

    If that takes care of your original question, please choose Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, if you have not already done so, you may not be aware that you can thank anyone who offered you help towards a solution for your issue by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of all those who offered help.

+ 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. Ampersand function, visible cells only, leading zeros for four digits.
    By dgulizio in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-08-2020, 05:01 PM
  2. Replies: 8
    Last Post: 06-03-2019, 10:48 AM
  3. Data Validation: 7 or 8 digits only, preserve leading zeros
    By Feefee32 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 06-26-2018, 12:47 PM
  4. Add leading zeros in same column numbers and text
    By rpinxt in forum Excel Programming / VBA / Macros
    Replies: 18
    Last Post: 07-29-2014, 04:41 PM
  5. Add leading zeros to select digits
    By Retro~Burn in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-29-2014, 06:14 AM
  6. Replies: 1
    Last Post: 09-28-2012, 03:40 PM
  7. formatted cell with leading zeros
    By ssdsibes in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-08-2009, 08:10 PM

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