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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
klikk680
Frequent Visitor

How to complete a field to get a fixed length with Power Query / M language

Hi,

I have this text column in my table

Label1 (txt)
12345678
NJGTWS21Q99Y651S

and I want a new column like this:

copy Label1 (txt)
0000000012345678
NJGTFS21P99Y651S

in excel I could use a function like:

=IF(LEN(a2)<16;(REPT("0";16-LEN(a2))&a2);a2)

How to complete this field to get a fixed length with Power Query / M language?

Thank you in advance!

1 ACCEPTED SOLUTION

Thanks @Anonymous I tried your suggestion with Text.PadStart function like this:

 

Text.PadStart([Label1 (txt)],16,"0") and it works fine!

 

Grazie 1000!

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

try using addcolumn with this formula:

 

Text.PadStart(Text.From([#"Label1 (txt)"]),16,"0")).

 

 

incidentally, for the excel version I would have this idea:

 

image.png

 

TESTO is the italian version of TEXT function RIPETI is for REPEAT and LUNGHEZZA is for LEN.

 

Thanks @Anonymous I tried your suggestion with Text.PadStart function like this:

 

Text.PadStart([Label1 (txt)],16,"0") and it works fine!

 

Grazie 1000!

Anonymous
Not applicable

Ma se il problema è, come mi viene il dubbio sia, la lettura di un codice fiscale come numero anziché testo, conviene piuttosto che affannarsi a cercare un rimedio, prevenire il problema in fase di caricamento dati.

Ad esempio, evitando che power query attui un cambio di tipo automatico sulle colonne che potrebbero sembrargli contenere dei nuemri invece sono testo a tutti gli effetti.

 

 

i dati purtroppo sono in questo formato nel csv che mi inviano, più che chiedere ogni volta di cambiare il formato non posso... 

grazie e buona giornata

--

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors