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

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

Reply
smko
Helper I
Helper I

Conditional column to match a range of substring

I have Column A from a dataset, I need to make the result into Column B, basically every result must have calling code in front.

smko_1-1623751539177.png

While I can write a really long ugly code something like below, is there anyway I could write it like Text.StartsWith([Column A], "01"&{"0".."9"}) so that I dont have to repeat for each combination. If possible I would like to stick to this type of solution, but I welcome other type of solution too.

= if (Text.StartsWith([Column A], "010") or Text.StartsWith([Column A], "011") or 
Text.StartsWith([Column A], "012") or 
Text.StartsWith([Column A], "013") or 
Text.StartsWith([Column A], "014") or 
Text.StartsWith([Column A], "015") or 
Text.StartsWith([Column A], "016") or 
Text.StartsWith([Column A], "017") or 
Text.StartsWith([Column A], "018") or 
Text.StartsWith([Column A], "019")) and 
Text.Length([Column A])>=10 and Text.Length([Column A])<=11 
then "+6"&[Column A]

 

 

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @smko 

How about

= if Text.StartsWith([Column A], "01") and List.Contains({"0".."9"}, Text.Middle([Column A],2))
and  Text.Length([Column A])>=10 and Text.Length([Column A])<=11 
then "+6"&[Column A] else null

You'll have to update the else clause

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

View solution in original post

2 REPLIES 2
AlB
Community Champion
Community Champion

Hi @smko 

How about

= if Text.StartsWith([Column A], "01") and List.Contains({"0".."9"}, Text.Middle([Column A],2))
and  Text.Length([Column A])>=10 and Text.Length([Column A])<=11 
then "+6"&[Column A] else null

You'll have to update the else clause

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

Excellent!! Thank you for saving my ugly code. There is one small mistake though, text.middle should be 

Text.Middle([Column A],2,1)

otherwise it grab entire string after 2nd position 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

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