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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
appsac1
Helper I
Helper I

Table.FindText returns more values than the only exact match

Hello,

 

couldn't find the solution, but probably it is something too easy. I'm using Table.FindText to merg a field from another table but in some instances it gives me more matches than I'd like. As an example I have one value 'apple' and I want to find the corresponding colours in another table. (apple > red, appletree > green). So I'm using:

 

Table.AddColumn(#"Previous step", "Colour of fruitthings", each Table.FindText(Fruitcolours, "apple") as a result i'm expecting only 'red' but i'd also get green because appletree. How do I solve this to only get 'red' and not green.

 

Kind regards,

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @appsac1 ,

 

To get only the exact match, you can use the Word.Starts function instead of Table.FindText. Word.Starts returns true if the first word in the text matches the search string. Here's how you can modify your code:

Table.AddColumn(#"Previous step", "Colour of fruitthings", each 
    let fruit = [Fruit Column Name],
        match = Table.SelectRows(Fruitcolours, each Word.Starts(Text.Trim([Fruit Column Name]), fruit)),
        color = if Table.RowCount(match) > 0 then match{0}[Color Column Name] else null
    in color
)

 


This code uses Table.SelectRows to filter the rows in the Fruitcolours table where the first word in the Fruit Column Name matches the search string. Then, it checks if there is at least one row in the filtered table and returns the value in the Color Column Name column of the first row if there is a match, or null otherwise.


Let me know if this helps.

 

                                                                                                                                                         

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.           

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @appsac1 ,

 

To get only the exact match, you can use the Word.Starts function instead of Table.FindText. Word.Starts returns true if the first word in the text matches the search string. Here's how you can modify your code:

Table.AddColumn(#"Previous step", "Colour of fruitthings", each 
    let fruit = [Fruit Column Name],
        match = Table.SelectRows(Fruitcolours, each Word.Starts(Text.Trim([Fruit Column Name]), fruit)),
        color = if Table.RowCount(match) > 0 then match{0}[Color Column Name] else null
    in color
)

 


This code uses Table.SelectRows to filter the rows in the Fruitcolours table where the first word in the Fruit Column Name matches the search string. Then, it checks if there is at least one row in the filtered table and returns the value in the Color Column Name column of the first row if there is a match, or null otherwise.


Let me know if this helps.

 

                                                                                                                                                         

Best Regards,

Stephen Tao

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.           

m_dekorte
Super User
Super User

Hi @appsac1,

 

Table.FindText returns a table containing only the rows that have the specified text within one of their cells or any part thereof. If you require an exact match use Table.SelectRows instead.

 

Table.AddColumn(#"Previous step", "Colour of fruitthings", each Table.SelectRows( Fruitcolours, (x)=> List.ContainsAny( Record.FieldValues(x), {"apple"} )))

 

There are many variations possible within Table.SelectRows 2nd argument but the important thing is that only rows that evaluate to true are retained.

 

Ps. Please mark this answer as solution when it helped you to resolve your question, thanks!

Hi m_dekorte, 

I had a similar problem and used your solution to solve it. It works, but I do have a hard understanding of how it works. Is it possible you could explain it in further detail, especially with the use of the variable.

 

Thanks in advance!

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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