PowerPivot - Padding with Zeros

ShaunP

New Member
Joined
Jul 5, 2018
Messages
10
I have a column of project numbers that vary in length. My plan is to write an IF statement to check the length of the Project Number and pad these numbers with 0 so that the formats are the same, max length of 10, if needed.

[TABLE="width: 500"]
<tbody>[TR]
[TD]Current Project Number[/TD]
[TD]New Proj Num[/TD]
[/TR]
[TR]
[TD]PRJ3[/TD]
[TD]PRJ0000003[/TD]
[/TR]
[TR]
[TD]PRJ0000012[/TD]
[TD]PRJ0000012[/TD]
[/TR]
</tbody>[/TABLE]

I'm using the MID & Format functions to find the location to start padding but it's not working for me.

Code:
=FORMAT(MID([ProjectNumber],4,len([ProjectNumber])),"0000000")

Using the code above will give a result of 3 and 0000012 for the 2 examples above.

I'm using the PowerPivot plugin for Excel 2010 (version 11.0.5058.0). I appreciate the help!
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
try:

=<br><span class="Keyword" style="color:#0070FF">LEFT</span><span class="Parenthesis" style="color:#969696"> (</span> [Current Project Number], <span class="Number" style="color:#EE7F18">3</span> <span class="Parenthesis" style="color:#969696">)</span><br>    & <span class="Keyword" style="color:#0070FF">REPT</span><span class="Parenthesis" style="color:#969696"> (</span> <span class="StringLiteral" style="color:#D93124">"0"</span>, <span class="Number" style="color:#EE7F18">10</span> - <span class="Keyword" style="color:#0070FF">LEN</span><span class="Parenthesis" style="color:#969696"> (</span> [Current Project Number] <span class="Parenthesis" style="color:#969696">)</span> <span class="Parenthesis" style="color:#969696">)</span><br>    & <span class="Keyword" style="color:#0070FF">MID</span><span class="Parenthesis" style="color:#969696"> (</span> [Current Project Number], <span class="Number" style="color:#EE7F18">4</span>, <span class="Number" style="color:#EE7F18">7</span> <span class="Parenthesis" style="color:#969696">)</span><br>
 
Upvote 0
try:

=
LEFT ( [Current Project Number], 3 )
& REPT ( "0", 10 - LEN ( [Current Project Number] ) )
& MID ( [Current Project Number], 4, 7 )

Thanks VBA Geek but that did not work. I get an error stating the REPT is the wrong data type. Both columns are formatted at Text.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top