Skip to content

Instantly share code, notes, and snippets.

@bjulius
bjulius / gist:ff2d3e50dd36b7bbe5cb5f757ee0d467
Created October 24, 2024 13:34
DAX SVG Measure to Generate IBCS-Style Bullet Charts
//Created by Brian Julius, 23 Oct 2024 using AI model o1-P
BulletChartSVG =
VAR __TotalSales = [Total Sales]
VAR __TargetSales = [Current Year Sales Target]
-- Normalize the bars by using the maximum target sales across all data
VAR __MaxTargetSales = [Max Sales Target]
-- Scale the bars based on the maximum target sales
@bjulius
bjulius / gist:e3d2ef512b8d0eab552ce6b326592200
Created October 9, 2024 13:12
Brian Julius Solution to Excel BI Challenge 561 - Maximum Profit
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
ToRows = Table.FromList( Table.ToRows( Source ), Splitter.SplitByNothing(), {"Trans"}),
BuySell = Table.AddColumn(ToRows, "BuySell", each [
a = [Trans],
b = List.Transform(a, each List.PositionOf(a, _)),
c = List.Transform(a, each 1),
d = Table.FromColumns( {a, b, c}, {"Buy", "BuyPos", "B1"}),
e = Table.FromColumns( {a, b, c}, {"Sell", "SellPos", "S1"}),
f = Table.SelectRows( Table.Join( d, "B1", e, "S1" ), each [BuyPos] < [SellPos]),
@bjulius
bjulius / gist:3aa8a47813582fd62f5949ce5dff7a0f
Created October 8, 2024 06:05
Batch file to extract BIM files from every PBIX file in a directory
REM Uses pbi-tools to extract the data model info and create the BIM file associated with each PBIX file in the directory
REM Batch file code written by Brian Julius, October 8, 2024
REM @echo off
SETLOCAL ENABLEDELAYEDEXPANSION
REM ============================================================
REM Batch Script to Extract BIM Files from PBIX Files
REM All PBIX files are in C:\test
REM All BIM files will be written to C:\test\bim_files
REM ============================================================
@bjulius
bjulius / gist:45edda84a1486eb2204d8c35daf684b7
Last active March 2, 2025 01:10
C# script for Tabular Editor/TE3 to extract table, column, relationship, and measure info in json format from Power BI PBIX files
//C# script for Tabular Editor/TE3 to extract table, column, relationship, and measure info in json format from Power BI PBIX files
//Written by Brian Julius, 3 Oct 2024
// Specify the output file path
string outputFile = @"C:\Temp\PowerBI_Model_Info.txt"; // Change this to your desired path
using (var writer = new System.IO.StreamWriter(outputFile))
{
// TMSCHEMA_TABLES
writer.WriteLine("TMSCHEMA_TABLES");
@bjulius
bjulius / gist:77eaf15909c1050a6da7d9fb5c2351cf
Created September 28, 2024 00:24
C# TE3 script to add measure name, measure description/purpose, and DAX code to the measure tooltip for each measure in a selected table
// C# TE3 script to add measure name, measure description/purpose, and DAX code to the measure tooltip for each measure in a selected table
// developed by Brian Julius, Sep 27, 2024
string apiKey = System.Environment.GetEnvironmentVariable("OPEN_AI_TE3_API_KEY");
if (string.IsNullOrEmpty(apiKey))
{
Error("API key not found in environment variable 'OPEN_AI_TE3_API_KEY'.");
return;
}
@bjulius
bjulius / gist:bbc4e6bb1788171c604d5511e4b62f92
Last active September 13, 2024 04:47
Privacy policy for M Code Styler Custom GPT
This GPT directly collects no data regarding your queries provided, and does not give Open AI permission to train its models
on the conversations with the GPT
It does use the Power Query formatter API, documented at https://www.durchblick-durch-daten.de/power-query/m-formatter/
This formatter does not collect any metadata, with the exception of Error tracking.
It does track Errors that occur during formatting in order to fix bugs and improve their service.
In these cases metadata about the error is sent to the azure app insights remote service which contains a stacktrace.
This stacktrace might indirectly contain some information about the query that caused the error
"gpt-4-turbo" meta [IsParameterQuery=true, List={"gpt-4o-mini", "gpt-4o", "gpt-4", "gpt-4-turbo"}, DefaultValue="gpt-4o-mini", Type="Text", IsParameterQueryRequired=true]
//Created by Brian Julius
//Contact me at: https://www.linkedin.com/posts/brianjuliusdc
//This query needs to accompany the M Code Help function, to allow selection of the appropriate GPT-4 series model.
let
AnalyzeDataWithChatGPT = (HelpRequest as text ) as text =>
let
apikey = Text.FromBinary(File.Contents("C:\temp\PQ_API_KEY.txt")),
GPTPrompt = Json.FromValue(
[
model = ModelToUse,
messages = {
[ role = "system", content = "You are an expert in Power Query and M code. Provide a clear, detailed answer to the question below related to M code. Include specific examples to help explain concepts" ],
[ role = "user", content = HelpRequest ]
@bjulius
bjulius / gist:d3404392474a0b474d95fe04c7ac5e87
Last active June 29, 2024 05:47
Python Script for GPT4O to Extract BIM from PBIX
import zipfile
import os
def extract_bim_from_pbix(pbix_path, output_dir):
# Ensure the output directory exists
os.makedirs(output_dir, exist_ok=True)
# Extract the pbix file (which is a zip file)
with zipfile.ZipFile(pbix_path, 'r') as pbix_zip:
# Extract all files to the output directory
@bjulius
bjulius / gist:7d1e9895205ecb654c805e64c28e1388
Created June 20, 2024 05:47
Brian Julius Solution to Omid Challenge 70
let
Source = Table.AddColumn(
Table.FromList({1, 2, 5, 10}, Splitter.SplitByNothing(), {"Denoms"}, null, null),
"Target",
each 11
),
Rscript = R.Execute(
"df <- dataset#(lf)coin_combinations <- function(target, coins) {#(lf) dp <- vector(""list"", target + 1)#(lf) dp[[1]] <- list(numeric(0)) #(lf) for (coin in coins) {#(lf) for (amount in coin:target) {#(lf) if (!is.null(dp[[amount - coin + 1]])) {#(lf) for (combination in dp[[amount - coin + 1]]) {#(lf) dp[[amount + 1]] <- append(dp[[amount + 1]], list(c(combination, coin)))#(lf) }#(lf) }#(lf) }#(lf) }#(lf) #(lf) return(dp[[target + 1]])#(lf)}#(lf)#(lf)target_sum <- max(df$Target)#(lf)coin_denominations <- as.vector(df$Denoms)#(lf)combinations <- coin_combinations(target_sum, coin_denominations)#(lf)max_length <- max(sapply(combinations, length))#(lf)padded_combinations <- lapply(combinations, function(x) {#(lf) length(x) <- max_length#(lf) return(x)#(lf)})#(lf)#(lf)combs_df <- do.call(