cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Robotman223 Frequent Visitor
Frequent Visitor

Add a Leading Zero within Column?

I have a column of data in which the lack of leading zero in the single digit numbers is causing plotting order issues.

I would like to add a leading zero to each single digit number, what is the easiest way to do this? I am very new to powerBI.

EG. "84-24M6 - Stage 1" to "84-24M6 - Stage 01"

 

Here is my data:

 

Column_name

84-24M6 - Stage 1

84-24M6 - Stage 2

84-24M6 - Stage 3

84-24M6 - Stage 4

84-24M6 - Stage 5

84-24M6 - Stage 11

84-24M6 - Stage 12

84-24M6 - Stage 13

84-24M6 - Stage 14

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
jborro Member
Member

Re: Add a Leading Zero within Column?

Hi @Robotman223 ,

 

Maybe not the tidiest solution, but if you always have the same string format:

Table.TransformColumns(Source, {{"Column_name", each Text.BeforeDelimiter(_, "Stage ") & "Stage " & Number.ToText(Number.FromText(Text.AfterDelimiter(_, "Stage ")), "0#"), type text}})

 

Kind regards,

JB 

View solution in original post

4 REPLIES 4
Highlighted
jborro Member
Member

Re: Add a Leading Zero within Column?

Hi @Robotman223 ,

 

Maybe not the tidiest solution, but if you always have the same string format:

Table.TransformColumns(Source, {{"Column_name", each Text.BeforeDelimiter(_, "Stage ") & "Stage " & Number.ToText(Number.FromText(Text.AfterDelimiter(_, "Stage ")), "0#"), type text}})

 

Kind regards,

JB 

View solution in original post

mcybulski Member
Member

Re: Add a Leading Zero within Column?

The solution below is similar to your answer jborro. Text.PadStart might offer the clean that you are looking for.

 

= Table.AddColumn(#"Filtered Rows", "Custom", each Text.BeforeDelimiter([Column_name], "Stage ")
& "Stage " &
Text.PadStart(Text.AfterDelimiter([Column_name], "Stage "),2,"0"))

 

Robotman223 Frequent Visitor
Frequent Visitor

Re: Add a Leading Zero within Column?

Thank you. However I am getting this error, any ideas?

 

Expression.Error: The name 'Filtered Rows' wasn't recognized. Make sure it's spelled correctly.

jborro Member
Member

Re: Add a Leading Zero within Column?

Hi @Robotman223

Change it to the name of whatever step is preceding this one (e.g. Source).

Kind regards,
John

Helpful resources

Announcements
New Ranks and Rank Icons in 2020

New Ranks and Rank Icons in 2020

Read the announcement for more information!

New Kudos Given Badges Coming

New Kudos Given Badges Coming

We're rolling out new Kudos Given badges. Find out how many Kudos you've given.

November 2019 Community Highlights

November 2019 Community Highlights

Get an overview of the events and great community content from November.

Power Platform World Tour

Power Platform World Tour

Find out where you can attend!

Top Solution Authors
Top Kudoed Authors (Last 30 Days)