Skip to content

Instantly share code, notes, and snippets.

View ImkeF's full-sized avatar

Imke Feldmann ImkeF

View GitHub Profile
let func =
// fetches the first N rows in all tables from a database at once and presents them in a compact form
(Server as text, Database as text, NumberOfRows as number) as table =>
let
Source = Sql.Database(Server, Database, [CreateNavigationProperties=false]),
#"Filtered Rows" = Table.SelectRows(Source, each Value.Is([Data], type table)),
#"Added Custom" = Table.AddColumn(#"Filtered Rows", "Custom", each Table.Transpose(Table.DemoteHeaders(Table.Buffer(Table.FirstN([Data],NumberOfRows))))),
#"Expanded Custom" = Table.ExpandTableColumn(#"Added Custom", "Custom", Table.ColumnNames(#"Added Custom"[Custom]{0}))
in
let func =
(SqlExpression as text) =>
let
Source = Expression.Evaluate(SqlExpression.ToExpression(SqlExpression, #shared), #shared) (#shared)
in
Source
, documentation = [
Documentation.Name = " Syntax.UseSQL
", Documentation.Description = " Use SQL-statement to query your M-tables (!!!) in your current file.
let func =
(TableColumn as list, optional SourceNameColumn as list) =>
let
AddIDs =
if
SourceNameColumn=null
then
TableColumn
else
let
// Removes all duplicate separators within a string. If optional "TrimEnds" is set to "yes" the (single remaining) separators will be removed from the start and end as well.
(MyText as text, Separator as text, optional TrimEnds as text) as text =>
let
TransformTextToList = List.Buffer(Text.ToList(MyText)),
Result = List.Accumulate(TransformTextToList, // List that will be iterated through
"", // a starting value (if necessary, here we leave it blank)
(resultSoFar, current) => if Text.End(resultSoFar,1) = Separator and current = Separator then resultSoFar else resultSoFar&current // operation that will be performed at each iteration-step
),
TrimEnd = if TrimEnds = "yes" then Text.TrimStart(Text.TrimEnd(Result, Separator), Separator) else Result
let func =
(ParChTable as table,
ChildKey as text,
ParentKey as text,
LevelColumnName as text) =>
let
/*//Debug Parameters
ParChTable = Nodes0,
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 =
(HTML as text) =>
let
// Use "Lines.FromBinary(Web.Contents("YourURL"))" to retrieve the HTML in text-form
Source = Text.From(HTML),
SplitAny = Text.SplitAny(Source,"><"),
ListAlternate = List.Alternate(SplitAny,1,1,0)
in
ListAlternate
let func =
(String as text, optional Delimiter as text) as text =>
let
delimiter = if Delimiter = null then " " else Delimiter,
TextToList = List.Buffer(Text.Split(String, delimiter)),
FilterList = List.Select(TextToList, each _ <> ""),
Result = Text.Combine(FilterList, delimiter)
in
Result
, documentation = [
let func =
(ZIPFile_path as text) =>
let
Header = BinaryFormat.Record([
MiscHeader = BinaryFormat.Binary(14),
BinarySize = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger32, ByteOrder.LittleEndian),
FileSize = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger32, ByteOrder.LittleEndian),
FileNameLen= BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger16, ByteOrder.LittleEndian),
ExtrasLen = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger16, ByteOrder.LittleEndian)
]),
(Table as table, Parent as text, Child as text, Qty as text) =>
let
/* Debug parameters
Table = tblBOM,
Parent = "ProductAssemblyID",
Child = "ComponentID",
Qty = "PerAssemblyQty",
*/