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
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
v-shex-msft
Community Support
Community Support

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
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
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.