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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ngct1112
Post Patron
Post Patron

M language: How to lookup value from Query1 to Query2

Hi,

 

To simplify, there are 2 queries which contain 1 column only separately.

Is it possible I could do something like, " If Query1 contains Query2 then Query2"?

Will be fine if there are any ways to get the same result. Thanks!

Query1
ABC1, 123, 234A
CDEF2-2, 15B
DEF3-12, 128C
EFGH4-543, 121D
FGH5, 23151, 2185E
GHI6, 21654, 18F
HIJ7, -2132, 213G
IJKLM8-8561, 0H
JKL9-21, 451I
KLMNOP0, 0, 11J

 

Query2
ABC1
CDEF2
DEF3
EFGH4
FGH5
GHI6
HIJ7
IJKLM8
JKL9
KLMNOP0

 

1 ACCEPTED SOLUTION
Geradav
Responsive Resident
Responsive Resident

@ngct1112 

 

You can also use the following without passing by an external custom function

Table.AddColumn(#"Changed Type", "OutputValue", (ValueToCompare) as text => Table.SelectRows(
  Query2Tbl, 
  each Text.Contains(ValueToCompare[Col1], [Col1])
){0}[Col1])

 

 

Hope That is helpful 

View solution in original post

6 REPLIES 6
Geradav
Responsive Resident
Responsive Resident

Hi @ngct1112 

 

You can create a custom function to evaluate and return the desired value, like this

(ValueToCompare as text) as text => let
  OutputValue = Table.SelectRows(Query2Tbl, each Text.Contains(ValueToCompare, [Col1]))
in
  OutputValue{0}[Col1]

Then you call that function in a Table.AddColumn()

 

Let us know if that works for you

 

Regards

 

David 

Geradav
Responsive Resident
Responsive Resident

@ngct1112 

 

You can also use the following without passing by an external custom function

Table.AddColumn(#"Changed Type", "OutputValue", (ValueToCompare) as text => Table.SelectRows(
  Query2Tbl, 
  each Text.Contains(ValueToCompare[Col1], [Col1])
){0}[Col1])

 

 

Hope That is helpful 

@Geradav , I have read some acticle but still do not figure out how to add and apply the custom function. May I know do you have any resource I could learn from.

However, the second formula is really awesome and it works incredibly!!

Great thanks! 

Geradav
Responsive Resident
Responsive Resident

@ngct1112 

The Power Query documentation from Microsoft at https://docs.microsoft.com/en-us/powerquery-m/ is surely a good start.

Then you can read "M is for data Monkey" https://www.skillwave.training/shop/m-is-for-data-monkey/

Read more articles and subscribe to some newsletters here https://www.poweredsolutions.co/

@Geradav Appreciated with your help and advise. Will follow the path to learn!

Mariusz
Community Champion
Community Champion

Hi @ngct1112 

 

You can use Merge Queries
https://www.youtube.com/watch?v=dTdFt9AvDHA

 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn


 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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