Skip to content

Instantly share code, notes, and snippets.

View ImkeF's full-sized avatar

Imke Feldmann ImkeF

View GitHub Profile
let
// ----------------------- Documentation -----------------------
documentation_ = [
Documentation.Name = " Dates.ListDateIntervals
", Documentation.Description = " Creates a list of dates according to the chosen interval between Start and End. Allowed values for 3rd parameter: ""Year"", ""Quarter"", ""Month"", ""Week"" or ""Day"".
" , Documentation.LongDescription = " Creates a list of dates according to the chosen interval between Start and End. The dates created will always be at the end of the interval, so could be in the future if today is chosen.
", Documentation.Category = " Table
", Documentation.Source = " http://www.thebiccountant.com/2017/12/11/date-datesbetween-retrieve-dates-between-2-dates-power-bi-power-query/ .
", Documentation.Author = " Imke Feldmann: www.TheBIccountant.com .
", Documentation.Examples = {[Description = " see http://www.thebiccountant.com/2017/12/11/date-datesbetween-retrieve-dates-between-2-dates-power-bi-power-query/ .
let
func = (JSON) =>
let
Source = JSON,
ParseJSON = try Json.Document(Source) otherwise Source,
TransformForTable =
if Value.Is(ParseJSON, type record) then
Record.ToTable(ParseJSON)
else
#table(
@ImkeF
ImkeF / Type.FromText
Last active October 15, 2024 16:40
Returns a type from its textual representation.
let func =
(TypeAsText as text) =>
Record.Field(
[type null = Expression.Evaluate( "type null", [ type null = type null] ),
type logical = Expression.Evaluate( "type logical", [ type logical = type logical] ),
type number = Expression.Evaluate( "type number", [ type number = type number] ),
Int64.Type = Expression.Evaluate( "Int64.Type", [ Int64.Type = Int64.Type] ),
type time = Expression.Evaluate( "type time", [ type time = type time] ),
type date = Expression.Evaluate( "type date", [ type date = type date] ),
type datetime = Expression.Evaluate( "type datetime", [ type datetime = type datetime] ),
///*
let func =
(ParChTable as table,
ChildKey as text,
ParentKey as text,
LevelColumnName as text) =>
//*/
let
let func =
(FileOrFolderPath as text) =>
let
CreateTable = if Text.End(FileOrFolderPath,5) = ".xlsx" or Text.End(FileOrFolderPath,5) = ".xlsm"
then #table({"Content", "Name"}, {{File.Contents(FileOrFolderPath), FileOrFolderPath}})
else Folder.Files(FileOrFolderPath) ,
FetchQueries = Table.AddColumn(CreateTable, "FetchQueries", each try fnFetchQueries([Content]) otherwise #table({"Column1"}, {{null}})),
#"Removed Other Columns" = Table.SelectColumns(FetchQueries,{"Name", "FetchQueries"}),
@ImkeF
ImkeF / Uri.UnescapeDataString.pq
Created August 1, 2023 20:51
Decodes special characters in the input data according to the rules of RFC 3986.
let func =
(data as text) as text =>
let
DecodedText = Uri.Parts("http://contoso?a=" & data)[Query][a]
in
DecodedText ,
documentation = [
Documentation.Name = " Uri.UnescapeDataString ",
Documentation.Description = " Decodes special characters in the input data according to the rules of RFC 3986. ",
Documentation.LongDescription = " Decodes special characters in the input data according to the rules of RFC 3986. ",
let func =
(ParChTable as table,
ChildKey as text,
ParentKey as text,
LevelColumnName as text) =>
let
/*//Debug Parameters
ParChTable = Nodes0,
let func =
(MyTable as table, MyColumnName as text) =>
let
Source = MyTable,
ShiftedList = {null} & List.RemoveLastN(Table.Column(Source, MyColumnName),1),
Custom1 = Table.ToColumns(Source) & {ShiftedList},
Custom2 = Table.FromColumns(Custom1, Table.ColumnNames(Source) & {"Previous Row"})
in
Custom2 ,
documentation = [
(Table as table, Parent as text, Child as text, Qty as text) =>
let
/* Debug parameters
Table = tblBOM,
Parent = "ProductAssemblyID",
Child = "ComponentID",
Qty = "PerAssemblyQty",
*/
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),