With this new custom function “List.SelectPositions” you can easily select items from a list by just passing a list of their positions within it as the parameter.
What it does
Say you have a list with numbers {1..5} and want to select the 1st, 4th and 5th element from it. Then you can pass these positions to the function as another list: {0, 3, 4}.
ListSelectPositions({1..5}, {0, 3, 4}) will return: {1,4,5}
You see that I’ve decided to follow the zero-based counting principle here, that you find throughout M in the query editor. If you don’t like that, you can use the optional 3rd parameter to let it start to count from 1 instead:
ListSelectPositions({1..5}, {1, 4, 5}, 1) will return {1, 4, 5}
But if you have entered positions that don’t exist, the function will return an error in their positions by default:
ListSelectPositions({1..5}, {1, 4, 5}) will return {2, 5, Error}
because there is no 6th element (you’ve omitted the 3rd parameter that allows you to start counting with 1).
But you can change this behaviour as well through the last optional 4th parameter: Setting it to 0 will fill the missing positions with null like this:
ListSelectPositions({1..5}, {1, 4, 5}, null, 0) will return {2, 5, null}
and setting it to 1 will eliminate it and shorten the list like this:
ListSelectPositions({1..5}, {1, 4, 5}, null, 1) will return {2, 5}
These additional error-handling-options of the 4th parameters are useful for dealing with badly formatted data and if you want to learn more about it, just let me know in the comments so that I can prioritize it.






