Skip to content

Instantly share code, notes, and snippets.

View cbaragao's full-sized avatar

Chris Aragao cbaragao

View GitHub Profile
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}}),
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
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
<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>
target card =
// unsat, below, near, hit
VAR _Q1_result = "unsat"
VAR _Q2_result = "below"
VAR _Q3_result = "near"
VAR _Q4_result = "hit"
Sparkline =
// dummy value in a table
VAR _vals = {
( 0, 500 ),
( 1, 700 ),
( 2, 1200 ),
( 3, 1250 ),
( 4, 550 ),
( 5, 780 ),
( 6, 990 ),
/*
Function: fnHoltWinters
Description: Trying to replicate HoltWinters quantitative smoothing with Power Query.
Author: Chris Aragao
Change Log:
11.13.2023 - Initial release. Initial code was based off of this tutorial: https://www.exceldemy.com/holt-winters-exponential-smoothing-in-excel/.
It was aimed at solely duplicating the output and did so.
@cbaragao
cbaragao / tableaujobs.ipynb
Created November 10, 2023 23:40
datajobs.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cbaragao
cbaragao / fnErlangC.pq
Last active July 9, 2024 11:52
Erlang C calculation in Power Query
let
fnErlangC =
(
number_of_calls as number,
period_of_minutes as number,
average_handling_time as number,
required_service_level as number,
target_answer_time as number,
maximum_occupancy as number,
// white wine dataset used from http://archive.ics.uci.edu/dataset/186/wine+quality
{
"data": {
"name": "dataset"
},
"params": [
{
"name": "grid",
"select": "interval",