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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
HH_95
Frequent Visitor

IF/AND/SEARCH column to find string and return new value

Hi all,

 

I have a column called 'Business Area' that can have several possible values, one of them being 'Clean'. I would like to separate 'Clean' into 'WP' and 'WD'. I would do this by looking at the 'Site' column and if it contains 'ABC' it would be 'WP' and if it doesn't contain 'ABC' it is 'WD'. The logic would look like;

 

1) IF 'Business Area'="Clean" AND 'Site' CONTAINS "ABC" then RETURN "WP"

2) IF 'Business Area' = "Clean" AND 'Site' DOES NOT CONTAIN "ABC" RETURN "WD"

3) IF "Business Area" IS NOT "Clean" RETURN 'Business Area'

 

Expected result:

Business AreaSiteBusiness area test
Cleanxxxx.WTWWP
Cleanxxxxxx.WPSWD
ERxxxxx.STFER
Cleanxxxxxxxx.SREWD

 

 

                

I have written this for the first part: 

Business area test = IF(AND(SEARCH("WTW",'SharePoint data'[Site],1,0)>0,'SharePoint data'[BusinessArea]="Clean"),"Water Production",'SharePoint data'[BusinessArea]) 

 

 

 

But require help to add statements 2 + 3 to complete this,

 

Thanks

 

 

1 ACCEPTED SOLUTION
MFelix
Super User
Super User

HI @HH_95 

 

Try the following code:

 

Business area test =
SWITCH (
    TRUE (),
    SEARCH ( "WTW", 'SharePoint data'[Site], 1, 0 ) > 0
        && 'SharePoint data'[BusinessArea] = "Clean", "Water Production",
    SEARCH ( "WTW", 'SharePoint data'[Site], 1, 0 ) = 0
        && 'SharePoint data'[BusinessArea] = "Clean", "WD",
    'SharePoint data'[BusinessArea] <> "Clean", 'SharePoint data'[BusinessArea]
)

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

3 REPLIES 3
Anonymous
Not applicable

HI @HH_95,

You can try to use the following calculated column formula if helps:

Business Area Replaced=
IF (
    'SharePoint data'[Business Area] = "Clean",
    IF ( SEARCH ( "ABC", 'SharePoint data'[Site], 1, 0 ) > 0, "WP", "WD" ),
    'SharePoint data'['Business Area']
)

Regards,

Xiaoxin Sheng

MFelix
Super User
Super User

HI @HH_95 

 

Try the following code:

 

Business area test =
SWITCH (
    TRUE (),
    SEARCH ( "WTW", 'SharePoint data'[Site], 1, 0 ) > 0
        && 'SharePoint data'[BusinessArea] = "Clean", "Water Production",
    SEARCH ( "WTW", 'SharePoint data'[Site], 1, 0 ) = 0
        && 'SharePoint data'[BusinessArea] = "Clean", "WD",
    'SharePoint data'[BusinessArea] <> "Clean", 'SharePoint data'[BusinessArea]
)

Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



HH_95
Frequent Visitor

Thanks, I used a slight variant(below) of this to get what i wanted.

 

Business area 2 = IF('SharePoint data'[BusinessArea]="Clean",SWITCH(TRUE(),CONTAINSSTRING('SharePoint data'[Site],"WTW"),"Water Production",not CONTAINSSTRING('SharePoint data'[Site],"WTW"),"Water Distribution"),'SharePoint data'[BusinessArea])

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.