Skip to content

Instantly share code, notes, and snippets.

View cbaragao's full-sized avatar

Chris Aragao cbaragao

View GitHub Profile
@cbaragao
cbaragao / Format_PQ_PAD.txt
Created February 9, 2025 22:10
Format PQ with Power Shell and Power Automate Desktop
SET PQ TO $fx'=Substitute(Code,Char(34),Concatenate("`", Char(34)) )'
Scripting.RunPowershellScript.RunPowershellScript Script: $fx'function FormatPQ {
param (
[string]$code,
[string]$resultType,
[int]$lineWidth = 80,
[int]$indentationLength = 2,
[bool]$includeComments = $true,
[bool]$surroundBracesWithWs = $false,
[bool]$indentSectionMembers = $true,
// get the outliers using quartiles
quartile_outliers =
LAMBDA(top_or_bottom, q, iqr,
IF(
LOWER(top_or_bottom) =
"top",
q + (1.5 * iqr),
q - (1.5 * iqr)
)
);
let
fnGetSQLServer =
let
GetSQLServerType = type function (
server as (
type text
meta [
Documentation.FieldCaption = "Server Name",
Documentation.FieldDescription = "SQL Server name",
Document.SampleValues = {"SERVER"},
let
// Define Power BI Parameter for Environment URL (Create this in Power BI)
EnvironmentURL = "yourorg.crm.dynamics.com", // Can be a Power BI parameter
// Connect to Dataverse (STATIC connection)
Source = CommonDataService.Database(EnvironmentURL, [CreateNavigationProperties = null]),
// Define Power BI Parameter for SQL Query (User-defined in Power BI)
SQLQuery = "SELECT * FROM systemuser", // Replace with your query
@cbaragao
cbaragao / Test.pq
Created October 31, 2024 01:57
This is a test
let
x=1,
y=2,
z=3
in
z
#change this to your desired file path and name
$xlfile = "$env:temp\dax2.xlsm"
Remove-Item $xlfile -ErrorAction SilentlyContinue
$Excel = ConvertFrom-Csv @"
Here is your file,
"@ | Export-Excel $xlfile -PassThru -AutoSize
$wb = $Excel.Workbook
$sheet = $wb.Worksheets["Sheet1"]
Add-Type -AssemblyName System.Windows.Forms
# Create a new form
$form = New-Object System.Windows.Forms.Form
$form.Text = "PQ File Selector"
$form.Size = New-Object System.Drawing.Size(400, 250)
$form.StartPosition = "CenterScreen"
# Create a listbox to display the file names
$listBox = New-Object System.Windows.Forms.ListBox
let
Switch = Function.From(
type function (value as any, l as list, default as any) as any,
(params) =>
let
// Function to select nth item of list
// If you pass in zero, you get even indices
// If you pass in one, you get odd indices
fnSelectEvenOdd = (lst as list, remainder as number) as list =>
let
(str as text, optional keep_upper as logical, optional keep_lower as logical, optional keep_nums as logical, optional keep_specials as logical, optional keep_chars as text) =>
let
// Function to remove characters from the string
fnRemove =
(string as text, l as list)=>
Text.Combine(
List.Select(
Text.ToList(str),
each List.Contains(l, Character.ToNumber(_))=false
),