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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Tcowley44
Regular Visitor

Add zero to any 7 digit number starting with 2 in power query

Hi all,

 

Trying to come up with a formula that will add a zero to any 7 digit number in a colum starting with a 2, nothing else. So far I get an error or add a zero to all 7 digit numbers. 

 

Thanks

1 ACCEPTED SOLUTION

Use this

= if Text.Length([Data])=7 and Text.Length(Text.Select([Data],{"0".."9"}))=7 and Text.Start([Data],1)="2" then "0"&[Data] else [Data]

View solution in original post

4 REPLIES 4
Vijay_A_Verma
Super User
Super User

I am not sure what is meant by adding 0 to this number. 

If you wanted that a 0 should come at the end, then use below formula

= if Number.IntegerDivide([Data],1000000)=2 then [Data]*10 else [Data]

If you wanted 0 as prefix, then the output will be in text format and you can use following formula in this case

= if Number.IntegerDivide([Data],1000000)=2 then "0"&Text.From([Data]) else [Data]

Hi Viay,

 

Thanks for the reply. A little more info. I need to add the 0 to the beggining of the number in my ship ref1 colum. the 7 digit numbers starting with 2 represent our PO#'s. They are supposed to have a zero and it isnt always included.  I still get an error when I tried you example. 

Tcowley44_0-1656608767265.png

 

 

 

Use this

= if Text.Length([Data])=7 and Text.Length(Text.Select([Data],{"0".."9"}))=7 and Text.Start([Data],1)="2" then "0"&[Data] else [Data]

Worked Perfectly! Thanks

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Top Solution Authors