Skip to content

Instantly share code, notes, and snippets.

@bjulius
bjulius / gist:bce9423676a0590184a7c9defc2c4719
Created January 29, 2024 08:35
Brian Julius Solution to Crispo Mwangi January 28 2024 Power BI Challenge
RawData Query =
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("LcvLDQAgDALQXXr2YD9qOkvj/mtooKcXAlRJTLmjxA7wACuTOjjaIyMK+hmLU3bebKDsotPnPg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Quantity = _t]),
ReType = Table.TransformColumnTypes(Source,{{"Quantity", Int64.Type}}),
AddIndex = Table.AddIndexColumn(ReType, "Index", 1, 1, Int64.Type)
in
AddIndex
Table Query
@bjulius
bjulius / gist:6f3afd6604b396216f5db4fa8d8ae310
Created February 5, 2024 20:03
Owen Price Power Query Challenge Feb 5, 2024 - Brian Julius Solution
let
Source = DataRaw,
AddDupe = Table.DuplicateColumn(Source, "Entry", "EntryDupe"),
SpltToRowsByAPS = Table.ExpandListColumn(Table.TransformColumns(AddDupe, {{"EntryDupe", Splitter.SplitTextByDelimiter("APS ", QuoteStyle.Csv), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "EntryDupe"),
FilterBlanks = Table.SelectRows(SpltToRowsByAPS, each ([EntryDupe] <> "")),
TrimEntryDuep = Table.TransformColumns(FilterBlanks,{{"EntryDupe", Text.Trim, type text}}),
SplitAmtByRSpace = Table.SplitColumn(TrimEntryDuep, "EntryDupe", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, true), {"EntryDupe.1", "Amount"}),
SplitDatebyRSpace = Table.RemoveColumns( Table.SplitColumn(SplitAmtByRSpace, "EntryDupe.1", Splitter.SplitTextByEachDelimiter({" "}, QuoteStyle.Csv, true), {"Deposit", "Date"}), "Entry"),
AddAPS = Table.TransformColumns(SplitDatebyRSpace,{{"Deposit", each Text.Insert(_ , 0, "APS "), type text}}),
SplitBySlash = Table.SplitColumn(T
@bjulius
bjulius / gist:6717f7139598f5954e3a55f39dd6a165
Created February 13, 2024 02:37
Owen Price Power Query Challenge Feb 12 2024 - Brian Julius Solution
let
String ="Amidst the ancient oak's shelter, the forest floor cradled fallen leaves. Leaves of gold, crimson, and russet danced in the autumn breeze. Breeze whispered secrets to the trees, and the trees listened, their branches swaying in rhythm. Rhythm of life echoed through the woodland—a symphony of rustling leaves and birdcalls. Birdcalls harmonized with the babbling brook, where water flowed over moss-covered stones. Stones, worn smooth by time, held stories of ages past. Past and present intertwined, as sunbeams filtered through the canopy, dappling the earth. Earth embraced memories, and memories lingered—a tapestry woven by seasons. Beneath the ancient oak, a squirrel gathered acorns, preparing for winter.",
Source = Web.BrowserContents("https://gist.github.com/ncalm/889ed38d780d653c4cce3d0df7f3d031"),
ExtractHTML = Html.Table(Source, {{"Column1", "TABLE.highlight.tab-size.js-file-line-container.js-code-nav-container.js-tagsearch-file > * > TR > :nth-child(1)"}, {"Column2", "TABLE.highli
@bjulius
bjulius / gist:b6c8adc5e5324a6dd728b3f38b4391ef
Created February 13, 2024 08:33
Excel BI Challenge 390 - Brian Julius Hybrid Power Query/R Solution
data <- dataset$Digits
find_n_digit_numbers_optimized <- function(n) {
start <- 10^(n-1)
end <- 10^n - 1
valid_numbers <- numeric(0)
for (num in start:end) {
digit_sum <- sum(as.numeric(unlist(strsplit(as.character(num), ""))))
@bjulius
bjulius / gist:d39d1922a7c1b5a12cc77308856b927f
Created February 17, 2024 06:41
Excel BI Power Query Challenge 157 - Brian Julius Solution
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
AddGlobalOrigOrder = Table.AddIndexColumn(Source, "GlobalOrigOrder", 0, 1, Int64.Type),
UnpivotOther = Table.UnpivotOtherColumns(AddGlobalOrigOrder, {"Group", "GlobalOrigOrder"}, "Attribute", "Value"),
SortNBuffer = Table.Buffer( Table.Sort(UnpivotOther,{{"Group", Order.Ascending}, {"Attribute", Order.Ascending}, {"GlobalOrigOrder", Order.Ascending}})),
Group = Table.Group(SortNBuffer, {"Group", "Attribute"}, {{"All", each _, type table [Group=number, GlobalOrigOrder=number, Attribute=text, Value=any]}}),
AddGlobalIdx1 = Table.AddColumn(Group, "GlobalIdx1", each Table.AddIndexColumn([All], "Global1", 1, 1)),
AddGlobalIdx0 = Table.SelectColumns( Table.AddColumn(AddGlobalIdx1, "GlobalIdx0", each Table.AddIndexColumn([GlobalIdx1], "Global0", 0, 1)), "GlobalIdx0"),
Expand = Table.ExpandTableColumn(AddGlobalIdx0, "GlobalIdx0", {"Group", "GlobalOrigOrder", "Attribute", "Value", "Global1", "Global0"}, {"Group", "GlobalOri
@bjulius
bjulius / gist:9940423079e266bf40914ccacf77499f
Created February 29, 2024 00:52
List. Accumulate vs List Transform
let
Source = {1..100000},
Accumulate =
List.Accumulate(
Source,
"",
( state, current ) => state & ( if state = "" then "" else ", " ) & Text.From( current )
),
SplitToList = List.Buffer( Text.Split(Accumulate, """, """)),
@bjulius
bjulius / gist:fffa738cd5e914a2bac88b56f28efc68
Last active March 4, 2024 02:34
Brian Julius Solution to CH-15 Transnformation
let
Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
AddAttrib = Table.AddColumn(Source, "Attrib", each [
a = {"A".."Z"},
b = List.PositionOf( a, [Product Code]) + 1
][b]),
Group = Table.Group(AddAttrib, {"Product Code"}, {{"All", each _, type table [Product Code=text, Ship Date=datetime, Po number=number, Po Quantity=number, Attrib=number]}}),
AddWGIndex = Table.RemoveColumns( Table.AddColumn(Group, "WithinGroupIndex", each Table.AddIndexColumn( [All], "WGIndex", 1, 1)), "All"),
Expand = Table.ExpandTableColumn(AddWGIndex, "WithinGroupIndex", {"Ship Date", "Po number", "Po Quantity", "Attrib", "WGIndex"}, {"Ship Date", "Po number", "Po Quantity", "Attrib", "WGIndex"}),
UnpivotOther = Table.UnpivotOtherColumns(Expand, {"Attrib", "WGIndex"}, "Attribute.1", "Value"),
@bjulius
bjulius / gist:e80cabe985a714bf608b7dba116e26e1
Created March 13, 2024 07:17
Excel BI Challenge 411 - Brian Julius solution
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
AddIndex = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type),
Dupe = Table.DuplicateColumn(AddIndex, "Sentences", "Sentences2"),
SplitToRows1 = Table.ExpandListColumn(Table.TransformColumns(Dupe, {{"Sentences2", Splitter.SplitTextByDelimiter(" """, QuoteStyle.None), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Sentences2"),
SplitToRows2 = Table.ExpandListColumn(Table.TransformColumns(SplitToRows1, {{"Sentences2", Splitter.SplitTextByDelimiter(""" ", QuoteStyle.None), let itemType = (type nullable text) meta [Serialized.Text = true] in type {itemType}}}), "Sentences2"),
IdentifyAddlSplits = Table.AddColumn(SplitToRows2, "Custom", each [
a = [Sentences],
b = Text.ToList( a ),
c = List.Select( b, each _ = """" ),
@bjulius
bjulius / gist:bd3ec8f41c69982a74165cf70430aa04
Last active March 15, 2024 10:27
Solution to Oz Du Soleil Excel PQ Challenge March 10 2024
let
Source2 = Table.FromList(List.Numbers(2013, 11), Splitter.SplitByNothing(), {"Year"}, null, ExtraValues.Error),
AddDay = Table.SelectRows( Table.AddColumn(Source2, "DayOfWeek", each Date.DayOfWeekName( #date( [Year], 10, 14))), each [DayOfWeek] = "Monday"),
Answer = List.Max(AddDay[Year])
in
Answer
@bjulius
bjulius / gist:24533d0a6eb4110fcebbb3c19e70ae44
Last active March 2, 2025 01:11
Melissa de Korte Extended Date Table
let fnDateTable = (#date(2022, 1, 1), #date(2024, 12, 31, optional FYStartMonthNum as number, optional Holidays as list, optional WDStartNum as number ) as table =>
let
FYStartMonth = if List.Contains( {1..12}, FYStartMonthNum ) then FYStartMonthNum else 1,
WDStart = if List.Contains( {0, 1}, WDStartNum ) then WDStartNum else 0,
CurrentDate = Date.From(DateTime.FixedLocalNow()),
DayCount = Duration.Days(Duration.From(EndDate - StartDate))+1,
Source = List.Dates(StartDate,DayCount,#duration(1,0,0,0)),
AddToday = if EndDate < CurrentDate then List.Combine( {Source, {CurrentDate}}) else Source,
TableFromList = Table.FromList(AddToday, Splitter.SplitByNothing()),
ChangedType = Table.TransformColumnTypes(TableFromList,{{"Column1", type date}}),