Skip to content

Instantly share code, notes, and snippets.

View cbaragao's full-sized avatar

Chris Aragao cbaragao

View GitHub Profile
<svg xmlns="http://www.w3.org/2000/svg" width="400" height="400" viewBox="0 0 400 400" fill="none">
<def>
<rect id="bgRect" width="150" height="150"/>
<rect id="fgRect" width="125" height="110" fill="white"/>
<rect id="noChange" width="20" height="5" fill="gray"/>
</def>
<g id="doGroup">
<use href="#bgRect" x="42" y="38" fill="#A5D0A8"/>
<use href="#fgRect" x="56" y="67"/>
<text id="header" x="100" y="60" fill="white" font-weight="bold" font-size="20">DO</text>
let
fnRoundDateTime = (dt as datetime, interval as number) =>
let
Source = Number.From(dt),
Minutes = 24 * 60 / interval,
Rounded = Number.RoundAwayFromZero((Source * Minutes), 0) / Minutes,
DateTime = DateTime.From(Rounded)
in
DateTime,
fnType = type function (dt as datetime, interval as number) as datetime
let fnCreateDimTables =
(t as table, optional exclusions as list) =>
let
// Get the schema for the table
Schema = Table.Schema(t),
// Select the text columns
AllTextCols = Table.SelectRows(Schema, each _[Kind] = "text")[Name],
let fnCreateDimID =
(fact as table, col_name as text)=>
let
fnCreateDim = (fact as table, col_name as text)=>
let
removed_cols = Table.SelectColumns(fact,{col_name}),
dedupe = Table.Distinct(removed_cols),
sorted = Table.Sort(dedupe,{{col_name, Order.Ascending}}),
(tbl as table, col_name as text, index_name as text)=>
let
removed_cols = Table.SelectColumns(tbl,{col_name}),
dedupe = Table.Distinct(removed_cols),
sorted = Table.Sort(dedupe,{{col_name, Order.Ascending}}),
add_index = Table.AddIndexColumn(sorted, index_name, 1, 1, Int64.Type),
order = Table.ReorderColumns(add_index,{index_name, col_name})
in
order
let
fnCreateMultiColDim = (t as table, dim_groups as list, id_names as list) =>
let
// This nested function creates the individual dimension tables within the List.Generate() run
fnMakeDim = (tbl as table, dim_cols as list, id_name as text) =>
let
// It add an index column after selecting the columns and deduplicating.
ChooseAndProcess = Table.AddIndexColumn(
Table.Distinct(Table.SelectColumns(t, dim_cols)),
id_name,
let fnCreateMultiDimID =
(fact as table, dim as table) =>
let
// Get column names minus the first column on the dim table, which should be the id
Columns = List.Skip(Table.ColumnNames(dim),1),
// Join the tables
Join = Table.Join(fact, Columns, dim, Columns),
(batch as number, total as number, base as number) =>
let
batches = List.Generate(
()=>[
from = base,
to = batch
],
each [to] <= total,
from datetime import date, timedelta
from dateutil.relativedelta import relativedelta
class DateGenerator:
def __init__(self):
self.fiscal_months = {1:10,2:11,3:12,4:1,5:2,6:3,7:4,8:5,9:6,10:7,11:8,12:9}
self.current_month = date.today().month
self.current_year = date.today().year
self.current_date = date.today()
let
fnSwitch = (string as text, switches as list, default as any) =>
let
// Get max index of replacement list
Max = List.Count(switches) - 1,
// Use List.Accumulate to loop through replacements
Switch = List.Accumulate(
switches,
default,
// if the string matches first index, then replace with second item in that nested list