Forum Discussion

ValeriaBreve's avatar
ValeriaBreve
Post Partisan
3 years ago
Solved

Create a list from one column excluding values from another

Hello! I have a query (QueryA) with a text column. I am collecting a list of text strings from another query (QueryB), and from this list I need to exclude what starts with any of the text in the c...
  • lbendlin's avatar
    lbendlin
    3 years ago

     

     

    let
      QueryB = {"Apples", "Zebras", "Bananas", "Veggies", "Pears", "Pea"}, 
      Source = #table({"Text"}, {{"App"}, {"Pe"}, {"Ban"}, {"All Others"}}), 
      #"Added Custom" = Table.AddColumn(
        Source, 
        "Column list", 
        (m) =>
          if m[Text] = "All Others" then
            List.Select(
              QueryB, 
              each Table.RowCount(Table.SelectRows(Source, (k) => Text.StartsWith(_, k[Text]))) = 0
            )
          else
            List.Select(QueryB, each Text.StartsWith(_, m[Text]))
      )
    in
      #"Added Custom"