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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
JayKobbieJnr
Regular Visitor

Power Query Text.insert with condition

Hello All, 

 

I am trying to do a text.insert for a report only when a condition is satisfied. I am not at liberty to divulve any part of the actual data, so unfortunately I can't provide any sample data. 

But basically, I would like to loop through the column "LC", check the length of the string for each row, if it is less than 3 then I will want to insert say 0 in postion 0 of the string, else I will keep the original string. Not sure if its a syntax problem or something else. Can anyone point me in the right dirrection? 

 

 

 

 

= Table.TransformColumns(#"Changed Type", {{"LC", each if Text.Length([LC]) ❤️ then Text.Insert([LC],0, "0") else [LC], type text}})

 

 

 

 

1 ACCEPTED SOLUTION
Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Text.Length([LC]) should be Text.Length([LC]) < 3

and whereever you have used LC, replace it with _

_ Means current record which is [LC}

Hence, your formula would become

 

= Table.TransformColumns(#"Changed Type", {{"LC", each if Text.Length(_)<3  then Text.Insert(_,0, "0") else _, type text}})

 

Also Text.Insert(_,0, "0") can be replaced with "0"&_ and also 1 { is sufficient, 2 { are not needed. 

= Table.TransformColumns(#"Changed Type", {"LC", each if Text.Length(_)<3  then "0"&_ else _, type text})

View solution in original post

2 REPLIES 2
JayKobbieJnr
Regular Visitor

Thanks a bunch @Vijay_A_Verma , that worked precisely. 

Vijay_A_Verma
Most Valuable Professional
Most Valuable Professional

Text.Length([LC]) should be Text.Length([LC]) < 3

and whereever you have used LC, replace it with _

_ Means current record which is [LC}

Hence, your formula would become

 

= Table.TransformColumns(#"Changed Type", {{"LC", each if Text.Length(_)<3  then Text.Insert(_,0, "0") else _, type text}})

 

Also Text.Insert(_,0, "0") can be replaced with "0"&_ and also 1 { is sufficient, 2 { are not needed. 

= Table.TransformColumns(#"Changed Type", {"LC", each if Text.Length(_)<3  then "0"&_ else _, type text})

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.