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

SEARCH FOR LETTER "A" AND "B" IN A TEXT AND PUT 1 ELSE 0 IN NEW COLUMN

I have a problem I have a strings something like below patterns:

A12345B, 12355, C56463D, A64631D,...

 

I want to create a simple column where I want to search for string that starts with A and ends with B and put 1 else 0? I would appreciate your help! I tried to use search and wildcards no luck! 

 

NEWCOLUMN=IF(SEARCH("A*B",TABLE[STRING],1,BLANK())>0,1,0)
1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

Here is one way to do it, that looks for A and B anywhere in the string.  

 

mahoneypat_0-1634945270308.png

 

Has A and B =
VAR searchtable =
    FILTER ( { "A""B" }, SEARCH ( [Value], 'Table'[String], 10 ) > 0 )
RETURN
    IF ( COUNTROWS ( searchtable ) = 210 )

 

 

If you need the match first/last, you can use this.

 

A Start B End = IF(Left('Table'[String], 1) = "A" && RIGHT('Table'[String], 1) = "B", 1, 0)
 
Pat




Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

3 REPLIES 3
v-yangliu-msft
Community Support
Community Support

Hi  @Mekan ,

Here are the steps you can follow:

1. Create calculated column.

NEWCOLUMN =
var _A=IFERROR(
SEARCH("A",[ID]),-1)
var _B=IFERROR(
SEARCH("B",'Table'[ID]),-1)
var _len=LEN('Table'[ID])
return
IF(
    _A=1&&_B=_len,1,0)

2. Result:

vyangliumsft_0-1635135822859.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

mahoneypat
Employee
Employee

Here is one way to do it, that looks for A and B anywhere in the string.  

 

mahoneypat_0-1634945270308.png

 

Has A and B =
VAR searchtable =
    FILTER ( { "A""B" }, SEARCH ( [Value], 'Table'[String], 10 ) > 0 )
RETURN
    IF ( COUNTROWS ( searchtable ) = 210 )

 

 

If you need the match first/last, you can use this.

 

A Start B End = IF(Left('Table'[String], 1) = "A" && RIGHT('Table'[String], 1) = "B", 1, 0)
 
Pat




Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Excellent, this is exactly what I wanted! I used your first/last solution and it worked perfectly! Thanks a lot for sharing! Have a great day!   

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.