Skip to content

Instantly share code, notes, and snippets.

View cbaragao's full-sized avatar

Chris Aragao cbaragao

View GitHub Profile
let
return = Table.FromRecords(
{
[
Name = "pqmath.Benford",
Function =
let
Benford = Function.From(
type function (num as number) as record,
let
pqmath.Benford =
let
Benford = Function.From(
type function (num as number) as record,
(params) =>
let
len = Text.Length(Text.From(params{0})),
first = if len >= 1 then Number.From(Text.ToList(Text.From(params{0})){0}) else null,
second = if len >= 2 then Number.From(Text.ToList(Text.From(params{0})){1}) else null,
let fnFactor =
(num as number) =>
let
fnFactors = (x as number) =>
List.Generate(
() => [f1 = 1, f2 = x, non_integer = true],
each [f1] <= num,
each [
f1 = [f1] + 1,
f2 = x / ([f1] + 1),
(t as table) =>
let
correlation = (x as list, y as list) =>
let
x1 = List.Transform(x, each Number.From(_)),
y1 = List.Transform(y, each Number.From(_)),
sum_x = List.Sum(x1),
sum_y = List.Sum(y1),
sum_x_sq = List.Accumulate(
x1,
let
Source = Excel.CurrentWorkbook(){[Name = "Table1"]}[Content],
base = Table.TransformColumnTypes(
Source,
{
{"Name", type text},
{"Date", type date},
{"Amount", Int64.Type},
{"Date2", type date},
{"Amount3", Int64.Type},
// First create the header of the SVG
Set(
varHeartHeader,
"<svg xmlns='http://www.w3.org/2000/svg' width='250' height='250' viewBox='0 0 250 250' fill='none'>
<rect width='250' height='250' fill='#F5F5F5'/>
<rect x='2.5' y='2.5' width='245' height='245' fill='white'/>
<rect x='2.5' y='2.5' width='245' height='245' stroke='#121C41' stroke-width='5'/>"
);
let
fnMegaStDevSample =
(l as list)=>
let
// function for trimmed average
fnGetTrimmed =
(lst as list)=>
let
DimDate =
VAR MinDate = DATE(2011,1,1)
VAR MaxDate = DATE(2030,12,31)
VAR PayPeriodStarts =
FILTER (
GENERATESERIES ( DATE ( 2010, 12, 19 ), DATE ( 2031, 1, 5 ), 14 ),
[Value] >= MinDate
&& [Value] <= MaxDate
)
VAR PayPeriodEnds =
let
fnMegaAverage =
(l as list)=>
let
// function for trimmed average
fnGetTrimmed =
(lst as list)=>
let
(z as number, stdev as number, population as number, optional mode as text)=>
let
// check optional parameter and default to s for sample
m = if mode = null then "s" else mode,
// subtract 1 from population for samples and make that default
n = if m = "p" then population else population -1,