+ Reply to Thread
Results 1 to 11 of 11

Power Query List.Contains

  1. #1
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    613

    Power Query List.Contains

    Hi,
    Can someone tell me what I'm doing wrong with List.Contains,
    I've looked at the ms doc and from description, cant see what's wrong,
    I have code ;
    Please Login or Register  to view this content.
    Which give false, it does contain A and B ? , if I change to Any, i get a a true,

    ??
    File attached,

    Richard.
    Attached Files Attached Files

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Power Query List.Contains

    Your first list does not have an item that is the list {"A","B"} which is why it returns false.
    Rory

  3. #3
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    613

    Re: Power Query List.Contains

    So it's not an OR criteria?

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Power Query List.Contains

    No, the second parameter is one value that has to match an item. That's why ContainsAny exists.

  5. #5
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    613

    Re: Power Query List.Contains

    So with List.Contains( {"A", "B", "C", "D", "E"} , {"A", "B"} ) ,

    List.Contai( { {"A","B"} , "B","C","D"} , {"A", "B"} ) is what I need. I think the penny's sought of dropped, just not sure

    how this is different from list.ContainsAll ( ?

    eg
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    but
    Please Login or Register  to view this content.
    just gets an error?


    I thought List.Generate( using records could get complicted,.

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Power Query List.Contains

    List.Contains only takes one value argument, so you can't just pass it 2 and hope for the best.

  7. #7
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    613

    Re: Power Query List.Contains

    This all started with uisng it as a filer in Table.SelecRows ;



    Alist = list of A and B values; [Item] = Column to filter down,

    Please Login or Register  to view this content.
    I get this is sending a true false to select rows and selecting those that are true, but it still has more than one value?
    I've attached workbook with this,



    Richard.
    Attached Files Attached Files

  8. #8
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,913

    Re: Power Query List.Contains

    No it doesn't have more than one value. The second argument is Item, which is a single value (for each row).

  9. #9
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    613

    Re: Power Query List.Contains

    Yes, I'd sort of realized that after replying. I'll mark this up closed.

    Thanks,

    RD

  10. #10
    Registered User
    Join Date
    08-22-2014
    Location
    472
    MS-Off Ver
    2010
    Posts
    1

    Re: Power Query List.Contains

    The List.Contains function can be a little tricky. Two things are confusing:

    1. List.Contains has a list as first argument, and a single value as second. However, it checks for an 'exact' match of the value searched, within the list.
    2. You can only provide a single value as second argument.



    Alternatively, you can use List.ContainsAny

    List.ContainsAny( {"A", "B", "C", "D", "E"} , {"A", "B"} )

    Cheers,
    Rick

  11. #11
    Forum Contributor
    Join Date
    08-03-2021
    Location
    London
    MS-Off Ver
    365
    Posts
    613

    Re: Power Query List.Contains

    Thanks,

    RD

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Power Query - Feeding dynamic sheet name to Power query
    By egoosen3 in forum Excel General
    Replies: 5
    Last Post: 09-13-2023, 07:41 AM
  2. [SOLVED] Power query concatenate to a list
    By Dicken in forum Office 365
    Replies: 2
    Last Post: 02-27-2023, 10:57 AM
  3. Transpose List in power query
    By JyothiGrace in forum Excel General
    Replies: 2
    Last Post: 07-01-2022, 08:45 AM
  4. Replies: 8
    Last Post: 10-21-2020, 03:02 AM
  5. [SOLVED] Power Query - excel formula translation into Power Query
    By afgi in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 02-19-2020, 03:38 AM
  6. Replies: 4
    Last Post: 02-17-2020, 06:03 AM
  7. Sub-Forum for Excel Power Tools (Power Query, Power Pivot & Power BI)
    By chullan88 in forum Suggestions for Improvement
    Replies: 10
    Last Post: 06-28-2018, 02:25 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1