Forum Discussion

kitala11's avatar
kitala11
Helper III
5 years ago
Solved

Stop PowerBI from adding zeros

Hi I have a column that looks like this in the csv file. 

Column

5788718

875802

7Y8561

0930349

 

However when I import it into PowerBI, it immediately automatically adds 0 in front of some of the numbers as shown eg. below.

Column

5788718

0875802

7Y8561

0930349

 

One way I stopped this is by converting the csv into excel file and change the whole column to TEXT format before importing so that it remains as the original data without any zeros added. However, is there anyway which I can solve this issue if I want to import directly using the csv file? 

Thanks in advance!

  • @kitala11, I doubt Power BI can't add 0 initials unless it's there at the source. Or some step in Power Query add that.

8 Replies

  • you should share your M code from Power BI Query Editor to see whats its doing with the source and possible motive from this added 0.

    • kitala11's avatar
      kitala11
      Helper III

      Hi this is the source query, which, when immediately execute upon importing, will already add the zeros

       

          Source = Csv.Document(File.Contents("C:(pseudofilelocation)\pseudofilename.csv"),[Delimiter=",", Columns=66, Encoding=1252, QuoteStyle=QuoteStyle.None]),

       

      I don't seem to find anything that can allow me to disallow powerBI from adding zero's automatically.

  • @kitala11, I doubt Power BI can't add 0 initials unless it's there at the source. Or some step in Power Query add that.

  • Hi kitala11 

    As the others have said, I don't see how PQ is adding a leading 0 unless you tell it to. That Source step just opens the CSV and I've just tested your code with the sample data and it imporst exactly as it is in the file.  There's nothing in it telling PQ to add a 0.

    So I have to conclude that either the data in the file already has the leading 0, or there's something in your query that adds it.

    Can you please share the entire CSV and query.

    regards

    Phil

    • kitala11's avatar
      kitala11
      Helper III

      Due to confidentiality, I cannot disclose the csv.

      However I can say that, I have repeatedly checked the csv, there is no leading 0 in the front.

      And that is also the entire query, I only imported it and did not make any other changes and there is no other parts to the query. Yet there is always that zero there when I just simply used get dataset>import csv. (no other actions done and I have already opened the csv file and checked the value myself, the value is exactly 875802 in the specific cell. yet appears as 0875802 immediately on import).

  • kitala11 

    Curious, if there are no other parts to the query where are you doing data transformations?  Are you doing everything in DAX?

    Are you seeing this leading 0 appear in the Power Query editor or in the Data tab?

    Also, the line of code you quoted ended with a , indicating there was more code after it.  If there wasn't, the code is invalid and would not run as the next section of code would be

     

    in
       Source

     

    Regards

    Phil

     

  • kitala11 if you need community help, you need to help by provide csv file (redact sensitive information) and send full Power Query rather than just replying and giving the full picture. What is the point of going back and forth, not helping to provide the correct information, and expecting help from the community? My 2 cents.

     

    Help us to get help.