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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
nr63bi
Helper I
Helper I

Extract specific text from a column

Hello,

 

I have a column with some values 

 

Exemple : 

 

P1,A,P2

P2,B,C,P1

P3,A,P1,D,E,G

 

Etc ...

 

I only want to extract P1, P2 and P3 (the result of what i want to extract is known) to result in

 

P1,P2

P2,P1

P3,P1

 

Do you know how to do this ? I have absolutely no idea ...

 

I thought of if Text in {"P1","P2","P3"} ...

 

Thank you in advance

2 REPLIES 2
tackytechtom
Super User
Super User

Hi @nr63bi ,


Here one way of doing this:

tackytechtom_0-1701117119948.png

 

Here the code in Power Query M that you can paste into the advanced editor (if you do not know, how to exactly do this, please check out this quick walkthrough)

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjDUcdQJMFKK1QGyjXScdJx1AgwhPGOQjKGOi46rjrtSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [column = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom", each Text.Split([column], ",")),
    #"Expanded Custom" = Table.ExpandListColumn(#"Added Custom", "Custom"),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Custom", each Text.Contains([Custom], "P1") or Text.Contains([Custom], "P2") or Text.Contains([Custom], "P3")),
    #"Grouped Rows" = Table.Group(#"Filtered Rows", {"column"}, {{"newcolumn", each Text.Combine( [Custom], ","), type text}}
)
in
    #"Grouped Rows"

 

Let me know, if this helps 🙂

 

/Tom
https://www.tackytech.blog/
https://www.instagram.com/tackytechtom/



Did I answer your question➡️ Please, mark my post as a solution ✔️

Also happily accepting Kudos 🙂

Feel free to connect with me on LinkedIn! linkedIn

#proudtobeasuperuser 

ronrsnfld
Super User
Super User

You can use the List.Intersect function:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WCjDUcdQJMFKK1QGyjXScdJx1AgwhPGOQjKGOi46rjrtSbCwA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Extract", each 
        Text.Combine(
            List.Intersect(
                {Text.Split([Column1],","),{"P1","P2","P3"}})
            ,","),type text)
in
    #"Added Custom"

ronrsnfld_0-1701116704215.png

 

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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