Skip to content

Instantly share code, notes, and snippets.

View ImkeF's full-sized avatar

Imke Feldmann ImkeF

View GitHub Profile
let func =
(function as function) =>
let
function_ = function,
Metadata = (functionType) as record =>
let
Help = Value.Metadata(if functionType is type then functionType else Value.Type(functionType))
in
Help,
let func =
(SourceTable as table, TermColumn as text, UntilTerm, optional KeepOrDrop, optional IgnoreCase) =>
let
Source = SourceTable,
Column = TermColumn,
UntilTerm = UntilTerm,
CaseSensitivity = if IgnoreCase = null then 0 else IgnoreCase,
Position = if List.Contains({"Yes",1}, CaseSensitivity)
then List.PositionOf(Table.Column(Source, Column), UntilTerm, Occurrence.First, Comparer.OrdinalIgnoreCase)
else List.PositionOf(Table.Column(Source, Column), UntilTerm),
let func =
(SelectionList as list, ListOfPositions as list, optional StartWithOne as number) =>
List.Transform(ListOfPositions, each try if StartWithOne = null then SelectionList{_} else SelectionList{_-1} otherwise null)
, documentation = [
Documentation.Name = " List.SelectPositions
", Documentation.Description = " Selects items from <code>SelectionList</code> by their positions in <code>ListOfPositions</code>
" , Documentation.LongDescription = " Selects items from <code>SelectionList</code> by their positions in <code>ListOfPositions</code>: https://wp.me/p6lgsG-N8 .
", Documentation.Category = " List
", Documentation.Source = " https://wp.me/p6lgsG-N8 .
let func =
(inputList as list, chunkSize as number) =>
let
ListSelectPositions = (SelectionList as list, ListOfPositions as list) => List.Transform(ListOfPositions, each try SelectionList{_} otherwise null),
Source = inputList,
ChunkSize = chunkSize,
Count = Number.RoundUp(List.Count(Source)/ChunkSize),
Chunks = {1..Count},
Positions = List.Transform(Chunks, each {_*ChunkSize-ChunkSize.._*ChunkSize-1}),
Allocate = List.Transform(Positions, each ListSelectPositions(Source, _))
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
let func =
(t as table, optional maxSample as number) =>
let
primitiveTypes = (t as table, optional maxSample as number) as table =>
let
Table = t,
MaxSample = maxSample,
Sample = if maxSample = null then Table.FirstN(Table,10) else Table.FirstN(Table,Number.From(maxSample)),
Columns = Table.ToColumns(Sample),
let func =
(Value as any) as text =>
let
t = Value.Type(Value),
nonNullableType = Type.NonNullable(t),
TypeDescription =
if Type.Is(nonNullableType, type number) then "number"
let func =
(Expression as any, Values as list, Results as list, optional Else as any) =>
try Results{List.PositionOf(Values, Expression)}
otherwise if Else = null then "Value not found"
else Else
, documentation = [
Documentation.Name = " M.Switch
", Documentation.Description = " Evaluates an <code>Expression</code> against a list of <code>Values</code> and returns one or multiple possible <code>Results</code> expressions.
" , Documentation.LongDescription = " Evaluates an <code>Expression</code> against a list of <code>Values</code> and returns one or multiple possible <code>Results</code> expressions.
let func =
(Table_ as table, newColumn as list, columnName as text) =>
let
ToColumns = Table.ToColumns(Table_),
FromColumns = Table.FromColumns(ToColumns&{newColumn}, Table.ColumnNames(Table_)&{columnName})
in
FromColumns
, documentation = [
Documentation.Name = " Table.AddColumnT
", Documentation.Description = " Adds a column to a <code>Table_</code> that originates from a list holding the values for the <code>newColumn</code> . New <code>columnName</code> to be passed as the last argument.
@ImkeF
ImkeF / power-query-iso-week-year.md
Created March 9, 2018 13:49 — forked from r-k-b/power-query-iso-week-year.md
M functions to convert between ISO 8601 Week & Year ⇄ dates (e.g., `2014-12-29` ⇄ `"2015-W01-1"`)