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
Anonymous
Not applicable

Checking for a string of cahracters

I need to find all the records that have columnA like "C12345". The value must begins with the letter "C" followed by 5 numbers. 

for example "C12345" is true but "C1234Y5" is false.

 

Thanks

2 ACCEPTED SOLUTIONS
rsbin
Super User
Super User

@Anonymous ,

Please try this as a Calculated Column:

Check = SWITCH(
            TRUE(),
            AND(( LEFT( [ColumnA], 1 ) = "C"), ISERROR( VALUE(MID( [ColumnA],2,5 ))) = FALSE() ), "True",
            "False" )

 

Regards,

View solution in original post

collinsg
Super User
Super User

Hello @Anonymous ,

Here's a suggestion using Power Query to add a custom true/false column, true for C12345 columns and false otherwise. You can then filter on the column. You may need an extra check like Text.Length(txt) = 6 if you wish true to be only when the string is 6 characters long.

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjY0MjYxVYrVgTIjIexkhLALugql2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ColumnA = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source, {{"ColumnA", type text}}),
#"Added Custom" = Table.AddColumn(
#"Changed Type",
"Valid",
each
let
txt = Text.Start([ColumnA], 6),
firstOK = Text.Start(txt, 1) = "C",
secondPart = Text.End(txt, 5),
secondOK = try Value.Type(Value.FromText(secondPart)) = Number.Type otherwise false,
result = firstOK and secondOK
in
result,
type logical
)
in
#"Added Custom"

 Hope this helps - example output.

collinsg_2-1721419929949.png

 

 

 

 

 

View solution in original post

2 REPLIES 2
collinsg
Super User
Super User

Hello @Anonymous ,

Here's a suggestion using Power Query to add a custom true/false column, true for C12345 columns and false otherwise. You can then filter on the column. You may need an extra check like Text.Length(txt) = 6 if you wish true to be only when the string is 6 characters long.

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcjY0MjYxVYrVgTIjIexkhLALugql2FgA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [ColumnA = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source, {{"ColumnA", type text}}),
#"Added Custom" = Table.AddColumn(
#"Changed Type",
"Valid",
each
let
txt = Text.Start([ColumnA], 6),
firstOK = Text.Start(txt, 1) = "C",
secondPart = Text.End(txt, 5),
secondOK = try Value.Type(Value.FromText(secondPart)) = Number.Type otherwise false,
result = firstOK and secondOK
in
result,
type logical
)
in
#"Added Custom"

 Hope this helps - example output.

collinsg_2-1721419929949.png

 

 

 

 

 

rsbin
Super User
Super User

@Anonymous ,

Please try this as a Calculated Column:

Check = SWITCH(
            TRUE(),
            AND(( LEFT( [ColumnA], 1 ) = "C"), ISERROR( VALUE(MID( [ColumnA],2,5 ))) = FALSE() ), "True",
            "False" )

 

Regards,

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