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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
jimmyhua
Helper I
Helper I

Compares a list of single values (list1) against a list of 2 values

compare_lists(list1, list2):

Compares a list of single values (list1) against a list of pairs (list2),
returning a list of indices where a match is found in the second list.

list1: List of single values.
list2: List of pairs (tuples or lists with 2 elements).

how to write using Power Query

1 ACCEPTED SOLUTION
slorin
Super User
Super User

Hi @jimmyhua 

 

= List.Transform(List1, (x) => List.PositionOf(List.Transform(List2, each List.Contains(_, x)), true) +1)

Stéphane 

View solution in original post

4 REPLIES 4
slorin
Super User
Super User

Hi @jimmyhua 

 

= List.Transform(List1, (x) => List.PositionOf(List.Transform(List2, each List.Contains(_, x)), true) +1)

Stéphane 

Omid_Motamedise
Super User
Super User

You can use List.Transform. Imagine List2 is {{1,2},{2,3},{2,4},{4,5}} and you are searching for 2 (it is better to be a value not list but if it was a single item list, use List1{0} to convert it to number), use the next formula to check which lists inside the second list include 2


List.Transform({{1,2},{2,3},{2,4},{4,5}}, each List.Contains(_,2))

If my answer helped solve your issue, please consider marking it as the accepted solution. It helps others in the community find answers faster—and keeps the community growing stronger!
You can also check out my YouTube channel for tutorials, tips, and real-world solutions in Power Query with the following link
https://youtube.com/@omidbi?si=96Bo-ZsSwOx0Z36h

here is two sample lists.  

list 1: = {"C",1,"D",4}
list 2: = {{1,"A"},{2,"B"},{3,"C"},{4,"D"}}

 

how to find each list 1 item in list 2 and provide a position number.  don't care whether it is the first item or the second item, just within which list2 pairs.

sanalytics
Super User
Super User

@jimmyhua 
Please go through the below link before posting any question here.
https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/td-p/144...
going forward please provide some dummy data along with your output screenshot. it will help us to provide the solution.

 

Regards,

sanalytics

 

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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