question

Lz-3068 avatar image
0 Votes"
Lz-3068 asked Lz-3068 commented

Power Query: Returning an ascribed list from a function

Hi. Example:

 let
     fxNumbers = (x, y) as list => {x..y},
     Source = #table(type table [Alpha=text], {
                 {"a"},{"b"}}),
     NewTable = Table.FromColumns(
         {
             List.Combine(Table.ToColumns(Source)),
             fxNumbers(1, 3)
         },
         {"Alpha", "Numbers"}
     )   // => [Numbers] type is any (not what I expect)
 in
     NewTable

So far the only way I've found (after searching and trying...) to return an ascribed list out of fxNumbers:

 fxNumbers = (x, y) as list =>
    Value.ReplaceType({x..y}, type {number})

Q: Is it the way to go or is there a better/recommended alternative?
Thanks

power-query-not-supported
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Ehren avatar image
1 Vote"
Ehren answered Lz-3068 commented

That's the best option I'm aware of, if you want the type to be dependent on what's returned from the function.

Alternatively, you can pass a table type to Table.FromColumns. For example:

 Table.FromColumns({ { {1,2,3}}}, type table [a={number}])
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks @Ehren. I was aware of the Table.FromColumns option :)

0 Votes 0 ·