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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Bertenvanloover
Frequent Visitor

How to find text from list in cell and return that text

Hi, I could use some help finding a way to do the manipulation below in Power Query:
I want to create 2 custom columns "Approver_Name1" and "Approver_Name2" that shows
* The Name of a person that was mentioned in column "T1Comment" based on table "Approver_Name_Table" and "No Approver" when there is no hit based on that table

* In case there are 2 names mentioned in the column "T1Comment" the second name should end up in "Approver_Name2"

Purpose: this table shows a history log of changes to the status of Documents, where each Document has a unique DocumentId. And I'd like to create an overview per approver so that that person gets an action list.
Bertenvanloover_0-1677237367879.png

 

DocumentIdTransitionNameT1CommentSubmittedDateApprover_Name1Approver_Name2
1Send for ApprovalTo be checked by Tom22/02/2023 11:00TomNo Approver
1Send back for EditingPlease change extension22/02/2023 11:01No ApproverNo Approver
1ApprovedApproved22/02/2023 11:02No ApproverNo Approver
2Send for ApprovalCapital mistake please check tom22/02/2023 11:05Tom 
2Send for ApprovalChecked by Tom & Bob22/02/2023 11:06TomBob
3Send for ApprovalTom/bob22/02/2023 11:00TomBob
3Send for ApprovalChecked byJay22/02/2023 11:02JayNo Approver
3Send for Approval2nd check jay22/02/2023 11:03JayNo Approver
3Send for ApprovalSend for Approval to Joe22/02/2023 11:05JeoffreyNo Approver
3ApprovedApproved22/02/2023 11:10No ApproverNo Approver
3Send back for EditingChange Editing Required11/09/2023 09:11No ApproverNo Approver

 

Approver_Name_Table

InputReference_Name
BobBob
bobBob
TomTom
JoeJeoffrey
JayJay
and so on......

 

This is only my second Power Query to date, so I'm a complete rookie. Thanks for the help!


Similar to: https://community.powerbi.com/t5/Power-Query/Query-to-create-column-comparing-text-value-to-column-i... 

Related to: https://community.powerbi.com/t5/Power-Query/Find-Text-from-List-in-Rows-with-same-ID-as-current-row... 

1 ACCEPTED SOLUTION
ImkeF
Community Champion
Community Champion

Hi @Bertenvanloover ,
one approach could be like so:

let
    Source = Excel.CurrentWorkbook(){[Name = "Main"]}[Content], 
    #"Changed Type" = Table.TransformColumnTypes(
        Source, 
        {
            {"DocumentId", Int64.Type}, 
            {"TransitionName", type text}, 
            {"T1Comment", type text}, 
            {"SubmittedDate", type any}, 
            {"Approver_Name1", type text}, 
            {"Approver_Name2", type text}
        }
    ), 
    #"Added Custom" = Table.AddColumn(
        #"Changed Type", 
        "Custom", 
        each Table.FromRows(
            {
                List.Distinct(
                    Table.SelectRows(Approver_Names, (a) => Text.Contains(Text.Lower([T1Comment]), Text.Lower(a[Input])))[Reference_Name]
                )
            }
        )
    ), 
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Column1", "Column2"}, {"Approver1", "Approver2"})
in
    #"Expanded Custom"

It has a different order of the values compared to your sample. Not sure if this is critical, else let me know.
Please also check the file enclosed.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

View solution in original post

2 REPLIES 2
Bertenvanloover
Frequent Visitor

Awesome, works like a charm! Thanks a lot for making my week 🙂

ImkeF
Community Champion
Community Champion

Hi @Bertenvanloover ,
one approach could be like so:

let
    Source = Excel.CurrentWorkbook(){[Name = "Main"]}[Content], 
    #"Changed Type" = Table.TransformColumnTypes(
        Source, 
        {
            {"DocumentId", Int64.Type}, 
            {"TransitionName", type text}, 
            {"T1Comment", type text}, 
            {"SubmittedDate", type any}, 
            {"Approver_Name1", type text}, 
            {"Approver_Name2", type text}
        }
    ), 
    #"Added Custom" = Table.AddColumn(
        #"Changed Type", 
        "Custom", 
        each Table.FromRows(
            {
                List.Distinct(
                    Table.SelectRows(Approver_Names, (a) => Text.Contains(Text.Lower([T1Comment]), Text.Lower(a[Input])))[Reference_Name]
                )
            }
        )
    ), 
    #"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", {"Column1", "Column2"}, {"Approver1", "Approver2"})
in
    #"Expanded Custom"

It has a different order of the values compared to your sample. Not sure if this is critical, else let me know.
Please also check the file enclosed.

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Kudoed Authors