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
LAHIRU92
Frequent Visitor

Add number or text to the middle of that value

I want to add "0" to third charactor position,if the legth of the text less than 6 charactors, otherwise need to dhow the original value,I wrote the sql code as below,but this did not give the current value if the length of the text more than 6 

 

if Text.Length[AR_ID]<6 then Text.Insert(Text.From[AR_ID],2,"0") else Text.From[AR_ID]

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

@LAHIRU92 Well LEN is the length function. I don't believe there is an equivalent for Insert, you would likely have to use STRING_SPLIT and then stich things back together. String Functions (Transact-SQL) - SQL Server | Microsoft Learn

 

Here is the IF statement definition: IF...ELSE (Transact-SQL) - SQL Server | Microsoft Learn



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Community Champion
Community Champion

@LAHIRU92 Pretty sure this is Power Query M code and not SQL and pretty sure you want this:

if Text.Length([AR_ID]) < 6 then Text.Insert(Text.From([AR_ID]),2,"0") else [AR_ID]


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thanks @Greg_Deckler , what is the SQL Code for above scenario 

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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 Solution Authors
Top Kudoed Authors