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
| (LeftTable as table, JoinColumns as list, RightTable as table, optional JoinColumnsRight as list, | |
| optional DuplicateColumnPrefix as text, optional JoinKind as number) => | |
| let | |
| //a function to handle null (optional) parameters | |
| fnIfNull = (arg1, arg2) => if arg1 = null then arg2 else arg1, | |
| //if join kind is null, default to inner join | |
| _JoinKind = fnIfNull(JoinKind, JoinKind.Inner), |
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
| /* | |
| Note, this function is used by the functions in the graph namespace | |
| */ | |
| IFOMITTED = LAMBDA(arg, then, [else], | |
| LET(_else, IF(ISOMITTED(else), arg, else), IF(ISOMITTED(arg), then, _else)) | |
| ); |
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
| /* | |
| A simple query to get the list of enumerations | |
| */ | |
| let | |
| Source = Web.Page(Web.Contents("https://learn.microsoft.com/en-us/powerquery-m/enumerations")){0}[Data] | |
| in | |
| Source |
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
| (typeTable as table) as list | |
| => | |
| let | |
| //check that the columns in the supplied table have the expected names | |
| checkColumnNames = Table.ColumnNames(typeTable) = {"ColumnName","Type"}, | |
| /* | |
| primitive types use this format in TransformColumnTypes | |
| type typeName | |
| Listed here are most common formats - full list on this page: |
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
| (parameterName as text) as table => | |
| let | |
| Source = Record.ToTable(#shared), | |
| AddColumn = Table.AddColumn( | |
| Source, | |
| "Params", | |
| each try Text.Combine(Record.FieldNames(Type.FunctionParameters(Value.Type([Value]))),", ") otherwise null | |
| ), | |
| Result = Table.SelectRows(AddColumn, each Text.Contains([Params],parameterName)) | |
| in |
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
| /* | |
| Creates an empty array of r rows and c columns | |
| Author: Owen Price | |
| Date: 2022-09-14 | |
| */ | |
| EMPTYARRAY = LAMBDA(r, [c], EXPAND({""}, r, IF(ISOMITTED(c), 1, c), "")); | |
| /* | |
| CROSSJOIN creates the cross-product of two arrays |
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
| /* | |
| from is the first integer in the list | |
| to is the target integer in the list | |
| step is the difference between successive integers | |
| */ | |
| L =LAMBDA(from,to,[step], | |
| LET( | |
| _step, IF(ISOMITTED(step), IF(from > to, -1, 1), step), | |
| //arguments should be single integers |
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
| /* | |
| array is a column of stuff to which we want to apply element function | |
| row_function is some function that produces an array with a fixed number of columns | |
| the column count produced by row_function must be identical regardless of input | |
| stack_function is one of V or H | |
| If you're unsure how these work or why we would use them, please review these videos: | |
| https://youtu.be/04jOeiMypXw | |
| https://youtu.be/wEBLT9QfQRw |
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
| (list1 as list, list2 as list) as list => List.TransformMany(list1, each list2, (x,y) => {x,y}) |
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
| /* | |
| Simple example of FOR JSON PATH | |
| With FOR JSON PATH, we can convert table data to JSON structured text. | |
| By using the . notation, we can create hierarchies of related attributes. | |
| */ | |
| SELECT TOP 5 * | |
| FROM DimCustomer; |