Skip to content

Instantly share code, notes, and snippets.

View cbaragao's full-sized avatar

Chris Aragao cbaragao

View GitHub Profile
Import-Module PSDuckDB
# Start timing
$startTime = Get-Date
# Parameters
$table = "test_table"
$sql = "SELECT * FROM $table"
$output = "Output\QueryResults.csv"
# Create a connection
// Moving Average
#r "Microsoft.VisualBasic"
using Microsoft.VisualBasic;
using System.Text.RegularExpressions;
// Select a measure
var offsetMeasure = Model.SelectMeasure();
// Select an offset column
/*
Benefit: Automatically removes projections from consideration
Make sure Dates[Year] and Dates[Month Name] are on the visual.
Example for a Matrix put these columns in the Rows well in this order
- Year
- Month Name
*/
#r "Microsoft.VisualBasic"
using Microsoft.VisualBasic;
using System.Text.RegularExpressions;
// Select a measure
var offsetMeasure = Model.SelectMeasure();
// Select an offset column
string offsetColumn = SelectColumn(Model.Tables["Dates"].Columns.Where(
col => col.Name.Contains("Offset")))
#r "Microsoft.VisualBasic"
using Microsoft.VisualBasic;
using System;
using System.Windows.Forms;
string stringInterval =
Interaction.InputBox(
Prompt: "Enter the interval for the moving average:",
Title: "Interval",
let
// Define the base API endpoint for the Dataverse environment
baseUrl = "https://your-org.crm.dynamics.com/api/data/v9.2/",
// Define the schema name of the environment variable you want to fetch
schemaName = "schema_name", // Replace with the actual schema name
// Fetch the environment variable definition that matches the given schema name
definitionQuery = Web.Contents(
baseUrl,
let
// Construct the URL to fetch environment variable values
values_url = Env
& "environmentvariablevalues?$select=environmentvariablevalueid,value,_environmentvariabledefinitionid_value",
// Retrieve the environment variable values from the OData feed
values = OData.Feed(values_url, null, [Implementation = "2.0"]),
// Construct the URL to fetch environment variable definitions
definition_url = Env
(
// table to pass in
tbl as table,
// name of the date column
date_column as text,
// name of the column you are projecting on
projection_column as text,
// "add", "mul", "None"
trend as text,
// "add", "mul", "None"
@cbaragao
cbaragao / FormatPQFromClipBoard.ps1
Created February 23, 2025 20:09
Format PowerQuery from Clipboard with PowerShell
function FormatPQ {
param (
[string]$code,
[string]$resultType,
[int]$lineWidth = 80,
[int]$indentationLength = 2,
[bool]$includeComments = $true,
[bool]$surroundBracesWithWs = $false,
[bool]$indentSectionMembers = $true,
[int]$alignLineCommentsToPosition = 0,
@cbaragao
cbaragao / Export-Workspaces.psm1
Created February 21, 2025 00:57
PowerShell module to export PBIX files and Dataflows from all identified workspaces and QA them
Function Set-Folders{
param (
[Parameter(Mandatory=$true)]
[string]$BasePath,
[Parameter(Mandatory=$true)]
[string]$ArchivePath,
[Parameter(Mandatory=$true)]
[string]$OutputPath,
[Parameter(Mandatory=$true)]
[string]$WorkspaceName