Skip to content

Instantly share code, notes, and snippets.

@bjulius
bjulius / gist:1c5c32b14029cbac0815ec3370ae791e
Created April 16, 2025 23:17
ggplot2 R Code for Horizontal Waterfall Chart
library(tidyverse)
library(patchwork)
library(ggtext)
# Create the data frame
df <- data.frame(
category = c(
"Machine sales", "Accessories sales", "Sales",
"Cost of sales", "Gross profit", "R&D costs",
"Sales costs", "Administration costs", "Net income"
@bjulius
bjulius / gist:6460802f1cb49e6e46479f3823ec5130
Created April 10, 2025 13:57
Default Definitions for R Anaconda Code
## Add imports
library(tidyverse)
## Configuration
options(warnPartialMatchDollar = TRUE)
## Define functions
## Pre-built utility functions
@bjulius
bjulius / gist:47264e8ba54704d7764ddd0ea3fd4b8f
Last active May 7, 2025 18:41
ggplot2 R code to create Nested Column Charts in Power BI
# This code creates an example Nested Column Chart of the type developed by Brittany Rosenau
# this code will produce the graphic below if you paste it into R Studio and run it
# to run it in a Power BI R visual, just import the csv into Power Query
# and then paste in the code below, changing df <- dataset
# note that "dataset" is the variable name used by convention in Power BI to call the table
# resulting from the previous step
# Load necessary libraries
library(ggplot2)
library(dplyr)
# Load necessary libraries
library(ggplot2)
library(dplyr)
library(tidyr)
library(gridExtra)
library(grid)
# Create the dataframe with the data from the image
sales_data <- data.frame(
Country = c("Finland", "Finland", "France", "France", "Netherlands", "Netherlands",
@bjulius
bjulius / gist:0f7b23ca1dd949980bbd9448603be7c3
Created March 1, 2025 22:54
Python in Power Query Script to Pull Current List of Open AI Model IDs
let
Source = "
import os
import openai
import pandas as pd
openai.api_key = os.getenv(""OPEN_AI_POWER_QUERY_API_KEY"")
response = openai.Model.list()
df = pd.DataFrame(response['data'])
",
RunPyScript = Python.Execute(Source),
@bjulius
bjulius / gist:03dc31ba83bf52d4eb2d7ee1417e48ba
Created February 28, 2025 12:21
Html for React Slider Component
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Moving Average Slider</title>
<style>
.slider-container {
display: flex;
align-items: center;
@bjulius
bjulius / gist:43cc197d68cb5faa208ab33d6aa25c89
Created February 27, 2025 16:09
C# Tabular Editor Script to Automate Commenting on DAX Measures
// C# script for Tabular Editor to document DAX measures using Claude 3.7 Sonnet API
// This script generates explanations for DAX measures and places the resulting info in the measures' metadata Description field
// Authored by Brian Julius, Feb 2025
#r "System.Net.Http"
#r "Newtonsoft.Json.dll"
#r "Microsoft.VisualBasic"
using System;
using System.Linq;
using System.Net.Http;
@bjulius
bjulius / gist:bbe97b5a954fc15fd58dea76e066e5b4
Last active April 16, 2025 01:47
DAX Measure to Extract Data Model Info for Prompting AI
BIM Info =
VAR TableInfo =
ADDCOLUMNS (
INFO.VIEW.TABLES (),
"Component", "Tables"
)
VAR ColumnInfo =
ADDCOLUMNS (
INFO.VIEW.COLUMNS (),
"Component", "Columns"
I had Deepseek R1 write the code for this solution, based on the following prompt:
Write M code that calls an R Script that uses a regex via the Stringer package to extract the dates in standard dd/mm/yyyy format from the left column. In the source column the year is specified first, then the month, then the day. Ignore any time values
@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