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
mshamsiev
Helper I
Helper I

Extracting Text from various places within a string

Hi all,

 

I have a column containing Priorities 1-4 in the format P1,P2 etc. which I'd like to isolate/extract.  

 

However, within the column, the entire string appears in various forms as seen below. I have attempted to use an if formula which has worked in extracting the 'P1' 'P2' format. However, how can I extract the 'Px' from the bottom format (TCS (SAP) etc.) THANKS!

 

SLA Definition

P4 - Incident

P2 - Incident

P1 - Incident

TCS (SAP) Resolve P4 SLA - Incident 

etc. 

1 ACCEPTED SOLUTION

Yes, it is Power BI, more specifically Power Query, accessible via "Edit Queries".

 

Even simplified further:

 

let
    Source = Table1,
    #"Added Custom" = Table.AddColumn(Source, "Priority", (This) => List.SingleOrDefault(List.Select({"P1","P2", "P3", "P4"}, each Text.Contains(This[SLA Definition],_)),""))
in
    #"Added Custom"
Specializing in Power Query Formula Language (M)

View solution in original post

6 REPLIES 6
v-chuncz-msft
Community Support
Community Support

@mshamsiev,

 

You could also try DAX function FIND and SEARCH.

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-chuncz-msft,

 

Hey again 🙂 Grateful for all the help mate! 

MarcelBeug
Community Champion
Community Champion

If the priority is always followed by a <blank>, this will work:

 

let
    Source = Table1,
    #"Added Custom" = Table.AddColumn(Source, "Priority", (This) => Text.Start(List.SingleOrDefault(List.Select({"P1 ","P2 ", "P3 ", "P4 "}, each Text.PositionOf(This[SLA Definition],_)>=0),""),2))
in
    #"Added Custom"

List.SingleOrDefault generates an error if >1 priority was found and it will return "" if no priority was found.

 

Edit: or even better:

 

let
    Source = Table1,
    #"Added Custom" = Table.AddColumn(Source, "Priority", (This) => Text.Start(List.SingleOrDefault(List.Select({"P1 ","P2 ", "P3 ", "P4 "}, each Text.Contains(This[SLA Definition],_)),""),2))
in
    #"Added Custom"

 

 

Specializing in Power Query Formula Language (M)

Hi @MarcelBeug,

 

Thanks for assisting mate! Does this formula apply to Power BI? 

 

Cheers,

Mike 

Yes, it is Power BI, more specifically Power Query, accessible via "Edit Queries".

 

Even simplified further:

 

let
    Source = Table1,
    #"Added Custom" = Table.AddColumn(Source, "Priority", (This) => List.SingleOrDefault(List.Select({"P1","P2", "P3", "P4"}, each Text.Contains(This[SLA Definition],_)),""))
in
    #"Added Custom"
Specializing in Power Query Formula Language (M)

@MarcelBeug, you sir are a true gentleman! Thanks again!

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.