Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
WJ876400
Helper IV
Helper IV

Adding 0 to id number

Hi

 

I have numerous spreadsheets and other source data that have an ID number, some sources have the ID with a 0 at the beginning and some dont and on my final input I have removed the 0. now I want to add it back in. The ID's have either 8 or 7 numbers in them, I want to add a zero to the beginning of the ID's with 7 numbers. Is that possible?

 

thanks

1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@WJ876400 

you can also use DAX to create a column

Column = FORMAT('Table (2)'[Column1],"00000000")

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

4 REPLIES 4
ryan_mayu
Super User
Super User

@WJ876400 

you can also use DAX to create a column

Column = FORMAT('Table (2)'[Column1],"00000000")

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




selimovd
Super User
Super User

Hey @WJ876400 ,

 

you can do that easily in Power Query with the Text.PadStart function.

See my example:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjQyVorVAdFgysQYShmCaWOIKJATCwA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ID = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", Int64.Type}}),
    #"Added Custom Column" = Table.AddColumn(#"Changed Type", "Custom", each Text.PadStart(Text.From([ID]), 3, "0"), type text)
in
    #"Added Custom Column"

 

In your case you just have to edit the PadStart to 7:

Text.PadStart(Text.From([ID]), 7, "0")

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

 

Hi Denis

 

Thank you so much for the quick response, sorry I am quite new in using Power BI, do I use this in the query editor? also do I input my ID column where you have "ID" also does it need to be a specifice type on output eg text, number?

Hi @WJ876400 

 

Please try to add a new custom column in Power Query as below:

VahidDM_1-1629207092309.png

 Use this code in the custom column:

 

Text.PadStart(Text.From([ID]), 8, "0")

 

 

The output will be as follow:

 

VahidDM_0-1629207000764.png

VahidDM_2-1629207160720.png

 

Did I answer your question? Mark my post as a solution!

Appreciate your Kudos VahidDM_3-1629207179882.png !!

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

Check out the February 2025 Power BI update to learn about new features.

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.