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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Super User
Super User

@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


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
Greg_Deckler
Super User
Super User

@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]

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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