Last active
April 16, 2021 12:40
-
-
Save ImkeF/01da3ce14b5d3e23715ccae36b57f820 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let func = | |
(SelectionList as list, ListOfPositions as list, optional StartWithOne as number, optional FillWithNulls as number) => | |
let | |
selectionList = List.Buffer(SelectionList), | |
listOfPositions = ListOfPositions, | |
StartPosition = if StartWithOne = 1 then -1 else 0, | |
Result = {List.Transform(listOfPositions, each selectionList{_ + StartPosition}), // null | |
List.Transform(listOfPositions, each selectionList{_+StartPosition}?), // 0 | |
Table.RemoveRowsWithErrors(Table.FromColumns({List.Transform(listOfPositions, each selectionList{_+StartPosition})})) //1 | |
}{List.PositionOf({null,0,1}, FillWithNulls)} | |
in | |
Result | |
, documentation = [ | |
Documentation.Name = " List.SelectPositions | |
", Documentation.Description = " Selects all items from <code>SelectionList</code> that are on positions in <code>ListOfPositions</code>. | |
" , Documentation.LongDescription = " Selects all items from <code>SelectionList</code> that are on positions in <code>ListOfPositions</code>. For the behaviour of the optional parameters see: https://wp.me/p6lgsG-N8 . | |
", Documentation.Category = " List | |
", Documentation.Source = " https://wp.me/p6lgsG-N8 . | |
", Documentation.Author = " Imke Feldmann: www.TheBIccountant.com . | |
", Documentation.Examples = {[Description = " For details see: https://wp.me/p6lgsG-N8 . | |
" , Code = " List.SelectPositions({1..5}, {0, 3, 4}) | |
", Result = " {1,4,5} | |
"]}] | |
in | |
Value.ReplaceType(func, Value.ReplaceMetadata(Value.Type(func), documentation)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Imke, Great packaging of the function!
btw what do you think if you use
"each SelectionList{_+StartPosition}?"
It will result in "cleaner" way of try X otherwise null