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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

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
Super User
Super User

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
Super User
Super User

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

Top Solution Authors
Top Kudoed Authors