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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Schnohren
Frequent Visitor

text.contains to use as lookup in another table in m power query akin to index match in excel

Hi all,

 

An issue I have been struggling with for some weeks now (more like driving me insane tbh) is adding a column to my main data table showing what group an item belongs to. The group column should be based on the item name in the main table and a lookup table stored elsewhere.

 

It is quite important that it is done in M so it is done in the data modelling.

 

So basically I want the below output:

 

Schnohren_0-1606393803710.png

based on this lookup table:

Schnohren_1-1606393844163.png

 

I was thinking the solution would be something like this going into the column ***Desired solution***:

 

if Text.Contains([Item], [Lookup_value]) = True then [Lookup_return] else null

 

 

However, I believe that I hit a snag because I am evaluating a text against a list, but I am not sure.

 

Any and all help is appreciated

 

Best regards,

Christian

 

1 ACCEPTED SOLUTION

Hi @Schnohren 

I think you can achieve your goal by merge and transform your table.

I build two sample tables like yours. I add a custom column in both tables for merge.

Merge = 1

Table1:

1.png

Lookup Table:

2.png

Choose Table1 to merge(lefter outer) two tables by merge columns.

Add a conditional column in New Table1.

3.png

Then we need to duplicate the New Table and group by Item to count null for each item.

4.png

We see item = pears 1 kg count = 10, others = 9, so we can distinguish that pears 1 kg = null others has result.

Merge New Table1 with this count table by Item, expand count column.

Remove "Merge","Lookup.Lookup_value","Lookup.Lookup_return" columns and remove duplicate column by selecting all remaining columns.

5.png

sort count column by ascending and sort Desired colution column by ascending.

Remove top 5 rows , count column and we can get the final result.

6.png

You can download the pbix file from this link: File.pbix

 

Best Regards,

Rico Zhou

 

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

5 REPLIES 5
Schnohren
Frequent Visitor

Hi @v-rzhou-msft

 

Wonderful job. Thanks for the help. 

 

Happy holidays. 🙂

 

BR Christian 

Schnohren
Frequent Visitor

Hi @amitchandak ,

 

Thanks for your response. I don't think it quite qualifies, because in the example you referred we have a one-to-many relation where we have a key (the CustomerName).

 

Here I want to check the Item column to see if it conatins any of the strings you can find in the Lookup_value column from the other table. Ideally, i would like to return the corresponding Lookup_return value.

 

\Christian

Hi @Schnohren 

I think you can achieve your goal by merge and transform your table.

I build two sample tables like yours. I add a custom column in both tables for merge.

Merge = 1

Table1:

1.png

Lookup Table:

2.png

Choose Table1 to merge(lefter outer) two tables by merge columns.

Add a conditional column in New Table1.

3.png

Then we need to duplicate the New Table and group by Item to count null for each item.

4.png

We see item = pears 1 kg count = 10, others = 9, so we can distinguish that pears 1 kg = null others has result.

Merge New Table1 with this count table by Item, expand count column.

Remove "Merge","Lookup.Lookup_value","Lookup.Lookup_return" columns and remove duplicate column by selecting all remaining columns.

5.png

sort count column by ascending and sort Desired colution column by ascending.

Remove top 5 rows , count column and we can get the final result.

6.png

You can download the pbix file from this link: File.pbix

 

Best Regards,

Rico Zhou

 

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

 

Anonymous
Not applicable

The lookup.Lookup_value never works. This is useless solution

amitchandak
Super User
Super User

@Schnohren , refer if this solution , if that can help

https://community.powerbi.com/t5/Desktop/How-to-lookup-values-in-another-table-in-the-Query-Editor/t...

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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 MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.