Page 2 of 2 FirstFirst 1 2
Results 11 to 14 of 14

Thread: Condense code to one Excel.CurrentWorkbook statement

  1. #11
    Super Moderator p45cal's Avatar
    Join Date
    Dec 2012
    Posts
    1,585
    Articles
    0
    Excel Version
    365


    Register for a FREE account, and/
    or Log in to avoid these ads!

    Quote Originally Posted by Bob Phillips View Post
    You have 2 good solutions, List.Contains and List.Intersect, which return a table with your required tables. .MatchesAny returns a logical comparing values to a condition, why would you want to go this way?
    Only academic, in process of exploring/experimenting/learning and getting my head around the functions and M language - that's all.
    Bill's proposal's List.IsEmpty also returns a logical but itself contains a List.Intersect, I was wondering if it could be done in one step with .MatchesAny.

  2. #12
    Acolyte cyborgski's Avatar
    Join Date
    May 2019
    Posts
    39
    Articles
    0
    Excel Version
    Office 365
    So building on Bill's solution and p45cal's academic desire to get the statement into one line, I propose the following:

    Code:
    let
            Source = Table.Combine(Table.SelectRows(Excel.CurrentWorkbook(), each List.Contains({"Table1","Table2","Table3"},[Name]))[Content])
    in
        Source
    I expect that it could also be done with a MatchesAny.
    Last edited by cyborgski; 2019-08-25 at 09:35 PM.

  3. #13
    Super Moderator Bob Phillips's Avatar
    Join Date
    Mar 2011
    Posts
    1,652
    Articles
    0
    Excel Version
    O365
    Okay Pascal, in the interest of understanding (), I came up with this
    Code:
    let
        _tables= {"Table1","Table2"},
        Source = Table.Combine(Table.SelectRows(Excel.CurrentWorkbook(), each List.MatchesAny(List.Intersect({{[Name]}, _tables}), each true))[Content])
    in
        Source

  4. #14
    Super Moderator p45cal's Avatar
    Join Date
    Dec 2012
    Posts
    1,585
    Articles
    0
    Excel Version
    365
    Thank you all, this has helped.

Page 2 of 2 FirstFirst 1 2

Posting Permissions

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