Skip to content

Instantly share code, notes, and snippets.

Avatar

David Eldersveld deldersveld

View GitHub Profile
View Power BI Python External Tool Sample - NO environment - PowerBIConnectionString.py
import sys
print('Power BI Desktop Connection')
print(str(sys.argv[1]))
print(str(sys.argv[2]))
print('')
conn = "Provider=MSOLAP;Data Source=" + str(sys.argv[1]) + ";Initial Catalog='';"
print(conn)
View Power BI Python External Tool Sample - NO environment - [tool].pbitool.json
{
"version": "1.0",
"name": "[Tool Name]",
"description": "[Tool Description]",
"path": "C:\\[PATH TO PYTHON EXECUTABLE]\\python.exe",
"arguments": "C:/[PATH TO PYTHON SCRIPT].py \"%server%\" \"%database%\"",
"iconData": "data:image/png;base64,[YOUR BASE64 IMAGE CONTENT]"
}
View Power BI Sparkline Column.DAX
Sparkline Column Categorical Axis =
// Static column color - use %23 instead of # for Firefox compatibility
VAR BarColor = "%2301B8AA"
VAR BarOutlineColor = "%23DDDDDD"
VAR BarOutlineWidth = 2
// Obtain number of columns - width generated based on column count (~20 column maximum for bar chart)
VAR BarCount = DISTINCTCOUNT('Table'[Customer Segment])
VAR BarWidth = INT(DIVIDE(100,BarCount))
// Obtain overall min and overall max measure values when evaluated for each column
VAR YMinValue = MINX(VALUES('Table'[Customer Segment]),CALCULATE([Measure Value]))
View Power BI Sparkline Line.DAX
Sparkline Line =
// Static line color - use %23 instead of # for Firefox compatibility
VAR LineColor = "%2301B8AA"
// "Date" field used in this example along the X axis
VAR XMinDate = MIN('Table'[Date])
VAR XMaxDate = MAX('Table'[Date])
// Obtain overall min and overall max measure values when evaluated for each date
@deldersveld
deldersveld / RGBDecimalColorToHex.dax
Created Jul 13, 2018
DAX - RGB Decimal Color to Hex
View RGBDecimalColorToHex.dax
RGB Decimal Color to Hex =
// Manually enter components of RGB decimal color value, e.g. "RGB(1,184,170)"
VAR RedDecimalColorValue = 1
VAR GreenDecimalColorValue = 184
VAR BlueDecimalColorValue = 170
//Decimal to Hex
VAR RedPosition0Dec = MOD(RedDecimalColorValue,16)
VAR RedPosition0Div = INT(RedDecimalColorValue / 16)
VAR RedPosition1Dec = MOD(RedPosition0Div,16)
VAR RedPosition1Div = INT(RedPosition0Div / 16)
@deldersveld
deldersveld / HexColorToRGB.dax
Last active Jul 13, 2018
DAX - Hex Color to RGB
View HexColorToRGB.dax
Hex Color to RGB =
VAR HexColorValue = "#01B8AA"
// Do not change anything below this line
VAR PositionRed1 = RIGHT(LEFT(HexColorValue,2),1)
VAR PositionRed0 = RIGHT(LEFT(HexColorValue,3),1)
VAR PositionGreen1 = RIGHT(LEFT(HexColorValue,4),1)
VAR PositionGreen0 = RIGHT(LEFT(HexColorValue,5),1)
VAR PositionBlue1 = RIGHT(LEFT(HexColorValue,6),1)
VAR PositionBlue0 = RIGHT(LEFT(HexColorValue,7),1)
VAR Red1 = SWITCH(PositionRed1,"A",10,"B",11,"C",12,"D",13,"E",14,"F",15,PositionRed1) * 16
View CombineTSVs.ps1
$getFirstLine = $true
get-childItem "[path]\*.tsv" | foreach {
$filePath = $_
$lines = $lines = Get-Content $filePath
$linesToWrite = switch($getFirstLine) {
$true {$lines}
$false {$lines | Select -Skip 1}
View ListAndDownloadAzureBlobContentByPrefix.ps1
Login-AzureRmAccount
$containerName = <<string containing container name>>
$storageContext = New-AzureStorageContext -ConnectionString <<connection string to storage account>>
$localDestinationPath = <<string containing file system path.>>
$blobPrefix = <<string containing prefix to search. wildcard character not needed after prefix.>>
#List
#Get-AzureStorageBlob -Context $storageContext -Container $containerName -Prefix $blobPrefix
@deldersveld
deldersveld / RemoveAzureBlobContainerByPrefix.ps1
Created Jan 3, 2018
Remove all blob containers and child blobs based on the specified container name prefix
View RemoveAzureBlobContainerByPrefix.ps1
Login-AzureRmAccount
$containerPrefix = <<string containing prefix to search. wildcard character not needed after prefix.>>
$storageContext = New-AzureStorageContext -ConnectionString <<connection string to storage account>>
Get-AzureStorageContainer -context $storageContext -prefix $containerPrefix | ForEach-Object {Remove-AzureStorageContainer -context $storageContext -Container $_.Name -Force}
@deldersveld
deldersveld / ATUS-ActivityLexicon.pq
Last active Dec 14, 2017
American Time Use Survey - Activity Lexicon from PDF
View ATUS-ActivityLexicon.pq
let
FilePath = "[replace with folder path]\tabula-lexiconnoex0315.csv",
Source = Csv.Document(File.Contents(FilePath),[Delimiter=",", Columns=6, Encoding=1252, QuoteStyle=QuoteStyle.Csv]),
#"Removed Top Rows" = Table.Skip(Source,1),
#"Promoted Headers" = Table.PromoteHeaders(#"Removed Top Rows", [PromoteAllScalars=true]),
#"Filtered Rows" = Table.SelectRows(#"Promoted Headers", each ([#"Major #(cr)category"] <> "ATUS 2003-2015 Activity coding lexicon" and [#"Major #(cr)category"] <> "Major #(cr)category")),
#"Replaced Value" = Table.ReplaceValue(#"Filtered Rows","",null,Replacer.ReplaceValue,{"Major #(cr)category", "First and #(cr)second-tier #(cr)categories"}),
#"Filled Down" = Table.FillDown(#"Replaced Value",{"Major #(cr)category", "First and #(cr)second-tier #(cr)categories"}),
#"Filtered Rows1" = Table.SelectRows(#"Filled Down", each ([#"6-digit #(cr)activity #(cr)code"] <> "")),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows1",{"", "_1"})