Skip to content

Instantly share code, notes, and snippets.

@grenzi
grenzi / azure-pipelines.yml
Created October 22, 2024 20:02
How to fetch tabular editor 2 and use in a pipeline on azure devops
trigger:
- main
pool:
vmImage: 'windows-latest'
steps:
- task: PowerShell@2
inputs:
targetType: 'inline'
@grenzi
grenzi / Test-PowerBIGateway.ps1
Created August 26, 2024 18:13
See if power bi on-prem data gateways are happily running / available, using a service principal account
Import-Module MicrosoftPowerBIMgmt
$clientId="REDACTED"
$tenantId="REDACTED"
$clientSecret="REDACTED"
$securePassword = ConvertTo-SecureString -String $clientSecret -AsPlainText -Force
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $clientId, $securePassword
Connect-PowerBIServiceAccount -ServicePrincipal -Credential $credential -TenantId $tenantId
# just a simple way to process an iterable in chunks
def batch(iterable, n=1):
l = len(iterable)
for i in range(0, l, n):
yield iterable[i:min(i + n, l)]
import locale, string
n = ['$1,234.56','-$1,234.56','($1,234.56)', '$ -1,234.56']
tbl = str.maketrans('(', '-', '$),')
[locale.atof( x.translate(tbl)) for x in n]
@grenzi
grenzi / RemoveHTML.m
Last active July 16, 2019 18:07
a pretty basic html to text conversion function for Power Query / Power BI use
let
Source = (txt as any) => let
removeOne = (input) =>
let
text = Text.From(input),
length = Text.Length(text),
position = Text.PositionOf(text, "<"),
positionEnd = Text.PositionOf(text, ">"),
range = positionEnd-position+1,
result = if position >= 0 then Text.ReplaceRange(text, position, range, "") else input
@grenzi
grenzi / Convert15To18.m
Last active December 8, 2023 16:06
Powerquery M function for Salesforce Id conversion to case insensitive (15 to 18 character)
(sf15Id as any) => let
Source = sf15Id,
#"tab" = #table(1, {{Source}}),
#"cb1" = Table.AddColumn(#"tab", "cb1", each if Text.Contains("ABCDEFGHIJKLMNOPQRSTUVWXYZ", Text.Middle([Column1],0,1)) then 1 else 0),
#"cb2" = Table.AddColumn(#"cb1", "cb2", each if Text.Contains("ABCDEFGHIJKLMNOPQRSTUVWXYZ", Text.Middle([Column1],1,1)) then 2 else 0),
#"cb3" = Table.AddColumn(#"cb2", "cb3", each if Text.Contains("ABCDEFGHIJKLMNOPQRSTUVWXYZ", Text.Middle([Column1],2,1)) then 4 else 0),
#"cb4" = Table.AddColumn(#"cb3", "cb4", each if Text.Contains("ABCDEFGHIJKLMNOPQRSTUVWXYZ", Text.Middle([Column1],3,1)) then 8 else 0),
#"cb5" = Table.AddColumn(#"cb4", "cb5", each if Text.Contains("ABCDEFGHIJKLMNOPQRSTUVWXYZ", Text.Middle([Column1],4,1)) then 16 else 0),
#"char16" = Table.AddColumn(cb5, "char16", each Text.Middle("ABCDEFGHIJKLMNOPQRSTUVWXYZ012345", [cb1]+[cb2]+[cb3]+[cb4]+[cb5], 1)),
#"cb6" = Table.AddColumn(#"char16", "cb6", each if Text.Contains("A
@grenzi
grenzi / dax_to_dataframe.py
Last active August 21, 2018 22:00
runs a dax query against SSAS and returns a dataframe
import clr
import pandas as pd
from tqdm import tqdm
clr.AddReference("System.Data")
import System.Data.OleDb as ADONET
def handle_oledb_field(f):
mytype=str(type(f))
if mytype == "<class 'System.DBNull'>":
return None
@grenzi
grenzi / Set-PsEnv.psm1
Last active February 21, 2023 23:11
sets powershell environment variables from python-dotenv formatted .env file
<#
.Synopsis
Exports environment variable from the .env file to the current process.
.Description
This function looks for .env file in the current directoty, if present
it loads the environment variable mentioned in the file to the current process.
based on https://github.com/rajivharris/Set-PsEnv