cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

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

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors