This file contains hidden or 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 | |
| colTypes = [ | |
| #"any" = Any.Type, | |
| #"date" = Date.Type, | |
| #"time" = Time.Type, | |
| #"datetime" = DateTime.Type, | |
| #"logical" = Logical.Type, | |
| #"number" = Number.Type, | |
| #"currency" = Currency.Type, | |
| #"integer" = Int64.Type, |
This file contains hidden or 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 | |
| /* This was an exercise just for fun. Who knows, it might have a real-world application... */ | |
| /* Generate every possible substring combination from a string */ | |
| getAllSubstrings = (s as text, optional makeDistinct as logical, optional ignoreCase as logical) as list => | |
| let | |
| c = if ignoreCase ?? false then Comparer.OrdinalIgnoreCase else Comparer.Ordinal, | |
| n = Text.Length(s), | |
| sub = List.TransformMany( | |
| {0..n-1}, | |
| each {_+1..n}, |
This file contains hidden or 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 | |
| fxErrorReport = (myTable as table, optional keyCols as list, optional scanCols as list ) as record => | |
| let | |
| colNames = Table.ColumnNames( myTable ), | |
| validKeys = List.Intersect( { colNames, keyCols ?? {} } ), | |
| hasKeys = List.Count( validKeys ) >0, | |
| selCols = List.Intersect( { colNames, scanCols ?? {} } ), | |
| nTable = Table.SelectColumns( myTable, if List.Count( selCols ) >0 then validKeys & selCols else colNames ), | |
| reservedNames = { "Name", "Errors", "Reason", "Message", "Detail", "rowIndex", "nCol" }, | |
| nameViolations = List.Intersect( { colNames, reservedNames } ), |
This file contains hidden or 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
| (t as table) as table => | |
| Table.Profile(t, | |
| {{ | |
| "ErrorCount", | |
| each true, | |
| each Table.RowCount(Table.SelectRowsWithErrors(Table.FromColumns({_}))) | |
| }} | |
| ) |
This file contains hidden or 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
| (t as table, optional replacementValue as any, optional scanCols as list) as table => | |
| let | |
| colNames = Table.ColumnNames(t), | |
| selCols = List.Intersect({colNames, scanCols ?? {}}), | |
| replErrors = Table.ReplaceErrorValues(t, | |
| List.Transform( | |
| if List.IsEmpty(selCols) then colNames else selCols, | |
| each {_, replacementValue} | |
| ) | |
| ) |
This file contains hidden or 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
| trimChar = LAMBDA(str, [char], [mode], | |
| LET( | |
| charToTrim, IF(ISOMITTED(char), " ", LEFT(char, 1)), | |
| trimMode, IF(OR(mode = 1, mode = 2, mode = 3), mode, 1), | |
| // Trim functions | |
| trimStart, LAMBDA(s, | |
| REDUCE( | |
| s, | |
| SEQUENCE(LEN(s)), | |
| LAMBDA(a, _, |
This file contains hidden or 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 | |
| fillRightOrLeft = ( tbl as table, optional fillCols as list, optional topRows as number, optional fillLeft as logical) as table => | |
| let | |
| fillFunction = if fillLeft ?? false then Table.FillUp else Table.FillDown, | |
| t = if topRows = null then tbl else Table.FirstN(tbl, topRows), | |
| allCols = Table.ColumnNames( tbl ), | |
| fillSideways = Table.TransformRows( t, | |
| each _ & Record.FromTable( | |
| fillFunction( Record.ToTable( | |
| Record.SelectFields(_, fillCols ?? allCols, MissingField.Ignore) |
This file contains hidden or 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
| ( tbl as table, optional fillCols as list, optional topRows as number, optional fillLeft as logical) as table => | |
| let | |
| fillFunction = if fillLeft ?? false then Table.FillUp else Table.FillDown, | |
| t = if topRows = null then tbl else Table.FirstN(tbl, topRows), | |
| allCols = Table.ColumnNames( tbl ), | |
| fillSideways = Table.TransformRows( t, | |
| each _ & Record.FromTable( | |
| fillFunction( Record.ToTable( | |
| Record.SelectFields(_, fillCols ?? allCols, MissingField.Ignore) | |
| ), {"Value"}) |
NewerOlder