Skip to content

Instantly share code, notes, and snippets.

@dgosbell
dgosbell / AutoPopulateMeasureDescriptionsFromOpenAIWithDelay.csx
Last active April 6, 2024 03:46
Update Tabular Model Descriptions from ChatGPT with rate limiting logic
#r "System.Net.Http"
using System.Net.Http;
using System.Text;
using Newtonsoft.Json.Linq;
// You need to signin to https://platform.openai.com/ and create an API key for your profile then paste that key
// into the apiKey constant below
const string apiKey = "<YOUR API KEY HERE>";
const string uri = "https://api.openai.com/v1/completions";
const string question = "Explain the following calculation in a few sentences in simple business terms without using DAX function names:\n\n";
// =====================================
// Author: Darren Gosbell
// Date: 12 Apr 2023
// This script works in Tabular Editor and sets the MaxParallelismPerQuery
// setting at the database level.
// =====================================
if (Model.Database.CompatibilityLevel < 1569)
{
Model.Database.CompatibilityLevel = 1569;
@dgosbell
dgosbell / AutoPopulateMeasureDescriptionsFromOpenAI.csx
Last active February 17, 2024 03:53
This is a script for tabular editor that will loop through all the measures in a model and get ChatGPT to write a description of the calculation.
#r "System.Net.Http"
using System.Net.Http;
using System.Text;
using Newtonsoft.Json.Linq;
// You need to signin to https://platform.openai.com/ and create an API key for your profile then paste that key
// into the apiKey constant below
const string apiKey = "<YOUR API KEY HERE>";
const string uri = "https://api.openai.com/v1/completions";
const string question = "Explain the following calculation in a few sentences in simple business terms without using DAX function names:\n\n";
@dgosbell
dgosbell / Move-PowerBICapacityWorkspaces.ps1
Last active December 3, 2023 23:45
Moves all Power BI / Fabric workspaces from one premium capacity to another. Useful for when you want to migrate between a P SKU and an F SKU and cannot simply scale up/down the existing SKU
#Requires -Modules MicrosoftPowerBIMgmt
<#
.SYNOPSIS
This script will move all workspace in one capacity to another capacity
.DESCRIPTION
.NOTES
File Name : Move-PowerBICapacityWorkspaces.ps1
Author : Darren Gosbell
@dgosbell
dgosbell / AutoPopulateMeasureDescriptionsFromAzureOpenAI.csx
Created March 29, 2023 22:33
Update Tabular Model Descriptions from Azure OpenAI with rate limiting logic
#r "System.Net.Http"
using System.Net.Http;
using System.Text;
using Newtonsoft.Json.Linq;
// you need to create a resource and deploy a model in Azure OpenAI
// to get the following 3 pieces of information
// see https://learn.microsoft.com/en-us/azure/cognitive-services/openai/how-to/create-resource?pivots=web-portal
const string apiKey = "<your API key";
const string resource_name = "<your resource name>";
@dgosbell
dgosbell / Add-PBIUserToRole.ps1
Last active June 25, 2023 23:59
Uses the XMLA endpoint to add a user to a role for a Power BI dataset
## NOTE: editing your dataset via the XMLA endpoint will prevent you from downloading it
## so make sure you have a backup of the original pbix file
$clientID = '<your-clientId>'
$clientSecret = '<your-client-secret>'
$tenantID = '<your-teantId>'
$workspaceName = 'Xmla%20Test'
$datasetName = 'Role Test'
$roleName = 'DynamicRole'
## This script will apply an incremental refresh policy to generate
## empty partitions for that policy using a Service Principal via the XMLA endpoint
$workspace = "XMLA%20Test"
$databaseName = "Adv Works Inc Refresh Base"
$tableName = "Internet Sales"
$clientID = "<Your SPN Client ID>"
$tenantID = "<Your TenantID>"
$clientSecret = "<Your SPN Secret>"
@dgosbell
dgosbell / deploy-BimFile.ps1
Created January 15, 2019 22:09
A simple example of how to manually deploy a model.bim file using Powershell
#Requires -Version 3.0
param(
[Parameter(Mandatory=$true)]
[string]$serverName,
[Parameter(Mandatory=$true)]
[string]$databaseName,
[Parameter(Mandatory=$true)]
[string]$pathToBimFile
)
$process = "MSMDSRV"
get-process -name $process | % {get-nettcpconnection -OwningProcess $_.id} | select-object @{Name="Process"; Expression = {$Process}},LocalPort, RemotePort, OwningProcess
$process = "PBIDesktop"
get-process -name $process | % {get-nettcpconnection -OwningProcess $_.id} | select-object @{Name="Process"; Expression = {$Process}},LocalPort, RemotePort, OwningProcess
### Author: Darren Gosbell (https://darren.gosbell.com)
### Date : 22 Jan 2021
### Usage : To use this script just update the following 4 variables for you environment
$server = "localhost\tab17"
$database = "adventure works"
$query = “evaluate 'Date'”
$filename = “c:\temp\tofile.csv”