Forum Discussion

Dicken's avatar
Dicken
Post Prodigy
7 months ago
Solved

Power Query List.Skip, Select


Can someone expalain why select / skip does not seem to handle errors,   I have read something about
lazy evaluation whch causes the whole thing to fail; so ; 

= let alist  = {"a","b","c",2,2,2} 
in 
List.Skip( alist, (x)=> 
Value.Is(x, type text) )
or
= let alist  = {"a","b","c",2,2,2} 
in 
List.Select( alist, (x)=> 
Value.Is(x, type text) )

thes work as expected, but is you cause an error, 

= let alist  = {"a"+2,"a","c",2,2,2} 
, skipper = List.Skip( alist, (x)=> not
Value.Is(x, type text) ) 
in skipper

So   the first value = error which is not text , so why does it not skip this and then continue, and is there a way to skip or select non error values? 

Richard


  • let 
        alist  = {"a"+2,"a","c",2,2,2},
        #"Removed Errors" = Table.RemoveRowsWithErrors(Table.FromColumns({alist}))[Column1],
        skipper = List.Select( #"Removed Errors", each Value.Is(_, type text) ) 
    in skipper
  • Function arguments are evaluated eagerily before they passed to a function body. So that your can't even use try ... otherwise from within a function to go around the error when your "x" argument in List.Skip is error itself. You need to use somthing that may contain this error - e.g. a table. This is what lbendlin did. Another example is 

        Table.Skip(
            Table.FromColumns({{"a"+2,"a","c",2,2,2}}, {"lst"}),
            (x) => try x[lst] is text otherwise true
        )[lst]

    Read Ben Gribaudo's Primer for more info about error handling in M. 

5 Replies

  • let 
        alist  = {"a"+2,"a","c",2,2,2},
        #"Removed Errors" = Table.RemoveRowsWithErrors(Table.FromColumns({alist}))[Column1],
        skipper = List.Select( #"Removed Errors", each Value.Is(_, type text) ) 
    in skipper
    • Dicken's avatar
      Dicken
      Post Prodigy

      Thanks, supprisingly tricky as it looks like quite a straighforward problem. 

  • Function arguments are evaluated eagerily before they passed to a function body. So that your can't even use try ... otherwise from within a function to go around the error when your "x" argument in List.Skip is error itself. You need to use somthing that may contain this error - e.g. a table. This is what lbendlin did. Another example is 

        Table.Skip(
            Table.FromColumns({{"a"+2,"a","c",2,2,2}}, {"lst"}),
            (x) => try x[lst] is text otherwise true
        )[lst]

    Read Ben Gribaudo's Primer for more info about error handling in M. 

    • Dicken's avatar
      Dicken
      Post Prodigy

      Thanks, yes I had tried nesting a try / otherwise within it and as you said it don't work.