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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
rchamberlain
Frequent Visitor

How to search a text column using a column list in another table and output first instance

Hello -

 

This situation seems so simple, but I'm struggling to get it to work.

 

I have two seperate tables and need to search a column in Table 1 using a list of values from a column in Table 2.

 

Example:

In Table1 I have a column called "Tags" with the following values listed in each.

 

Table1[Tags]

Tags
condition-4; condition-4.2; condition-3
condition-9; condition-5; condition-10
condition-8; condition-7; condition-6

 

I'm trying to create a calculated column that searches this field using a column in Table2 like this.

 

Table2[Condition_Name]

Condition_Name
condition-10
condition-9.1
condition-9
condition-8
condition-7
condition-6
condition-5
condition-4.2
condition-4.1

condition-4

 

What I need the calculated column to do is search Table1 using the values in Table2 and output the first instance starting from Top to bottom.

 

Expected output for the new calculated column in Table1

 

TagsNew Calculated Column
condition-4; condition-4.2; condition-3condition-4.2
condition-9; condition-5; condition-10condition-10
condition-8; condition-7; condition-6condition-8

 

I hope this makes sense and would be very greatful if someone can help!

 

Thanks,

Rich

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@rchamberlain,

 

Try this solution.

 

1. Create an Index column in Power Query for Table2 (Condition_Name).

 

DataInsights_0-1731088023455.png

 

DataInsights_1-1731088048214.png

 

2. Create calculated column in Table1 (Tags).

 

New Calculated Column = 
VAR vTag = Tags[Tags]
// get the minimum index (multiple matches may occur)
VAR vMinIndex =
    MINX (
        FILTER (
            Condition_Name,
            CONTAINSSTRING ( vTag, Condition_Name[Condition_Name] )
        ),
        Condition_Name[Index]
    )
VAR vResult =
    // get the condition name corresponding to the minimum index
    MAXX (
        FILTER ( Condition_Name, Condition_Name[Index] = vMinIndex ),
        Condition_Name[Condition_Name]
    )
RETURN
    vResult

 

DataInsights_2-1731088192358.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
DataInsights
Super User
Super User

@rchamberlain,

 

Try this solution.

 

1. Create an Index column in Power Query for Table2 (Condition_Name).

 

DataInsights_0-1731088023455.png

 

DataInsights_1-1731088048214.png

 

2. Create calculated column in Table1 (Tags).

 

New Calculated Column = 
VAR vTag = Tags[Tags]
// get the minimum index (multiple matches may occur)
VAR vMinIndex =
    MINX (
        FILTER (
            Condition_Name,
            CONTAINSSTRING ( vTag, Condition_Name[Condition_Name] )
        ),
        Condition_Name[Index]
    )
VAR vResult =
    // get the condition name corresponding to the minimum index
    MAXX (
        FILTER ( Condition_Name, Condition_Name[Index] = vMinIndex ),
        Condition_Name[Condition_Name]
    )
RETURN
    vResult

 

DataInsights_2-1731088192358.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Thanks for the quick reply!  This worked perfectly!

 

lbendlin
Super User
Super User

and output the first instance starting from Top to bottom.

Power BI has no concept of that.  You need to indicate what you mean by "top" or "bottom".  Usually by adding an index column

 

lbendlin_0-1731087313170.png

 

Your request doesn't seem to depend on user input, so instead of doing it as a calculated column you could also decide to do it in Power Query.

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSs7PS8ksyczP0zWxVkDi6Bkhc42VYnWQ1VoiS5oicwwN0JRaIMuaI3PMlGJjAQ==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Tags = _t]),
    #"Added Custom" = Table.AddColumn(Source, "Custom Column", each List.Intersect({Text.Split([Tags],"; "),#"Condition_Name"[Condition_Name]})),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom", (k)=> List.First(Table.Sort(Table.SelectRows(#"Condition_Name",each List.Contains(k[Custom Column],[Condition_Name])),"Index")[Condition_Name])),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom1",{"Custom Column"})
in
    #"Removed Columns"

 

lbendlin_1-1731088181061.png

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors
Top Kudoed Authors