Skip to content

Instantly share code, notes, and snippets.

@Erik-H-zz
Erik-H-zz / streaming_cpu.ps1
Created December 9, 2020 09:10
Write Cpu and Memory to a Power BI Streaming dataset
$endpoint = "<<Your Endpoint comes here>>"
while($true)
{
$ComputerCPU = (Get-WmiObject -Class win32_processor -ErrorAction Stop | Measure-Object -Property LoadPercentage -Average | Select-Object Average).Average
$ComputerMemory = Get-WmiObject -Class win32_operatingsystem -ErrorAction Stop
$UsedMemory = $ComputerMemory.TotalVisibleMemorySize - $ComputerMemory.FreePhysicalMemory
@Erik-H-zz
Erik-H-zz / LatestCPU.dax
Created December 9, 2020 09:45
CPU, TopN 1 Time
Lastest CPU =
VAR TopNTime = TOPN(1 , RealTimeData , RealTimeData[Time] ,DESC )
return
CALCULATE(min(RealTimeData[CPU]) , TopNTime)
Threshold (average past 5) =
VAR top5 = TOPN( 5, RealTimeData , RealTimeData[Time] , DESC)
RETURN
CALCULATE(AVERAGE(RealTimeData[CPU]) , top5 )
IsAboveThreshold = IF([Lastest CPU] > [Threshold (average past 5)] +5 , 1 , 0)
{
"type": "AdaptiveCard",
"body": [
{
"type": "ColumnSet",
"separator": true,
"columns": [
{
"type": "Column",
"width": "stretch",
#Log in to Power BI Service
Login-PowerBI -Environment Public
#First, Collect all (or one) of the workspaces in a parameter called PBIWorkspace
$PBIWorkspace = Get-PowerBIWorkspace # Collect all workspaces you have access to
#$PBIWorkspace = Get-PowerBIWorkspace -Name 'My Workspace Name' # Use the -Name parameter to limit to one workspace
#Now collect todays date
$TodaysDate = Get-Date -Format "yyyyMMdd"
@Erik-H-zz
Erik-H-zz / .json
Last active November 11, 2021 12:32
{"type":"FeatureCollection", "features": [
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-0.08555539569718484,51.51981579755783],[-0.0834559420329396,51.51981579755783],[-0.08141032051393143,51.52091610672171],[-0.08141032051393143,51.522016415885574],[-0.07828805609018208,51.522016415885574],[-0.07931086684968619,51.518715488393966],[-0.07828805609018208,51.518715488393966],[-0.07721141318544089,51.516514870066224],[-0.07408914876169159,51.51431425173849],[-0.07306633800218748,51.51211363341075],[-0.07306633800218748,51.50991301508301],[-0.07516579166643272,51.50991301508301],[-0.07618860242593684,51.51101332424688],[-0.07931086684968619,51.50991301508301],[-0.07931086684968619,51.507712396755274],[-0.08141032051393143,51.50881270591914],[-0.0886776601209342,51.50881270591914],[-0.09179992454468355,51.50991301508301],[-0.09599883187317404,51.50991301508301],[-0.1001439070564275,51.51101332424688],[-0.11161015399192076,51.51101332424688],[-0.11161015399192076,51.51541456090236],[-0.113655775
@Erik-H-zz
Erik-H-zz / PreviousDateofSales.dax
Created March 1, 2022 17:15
Get the previous date of sales
Previous Date of Sales =
MAXX(
ADDCOLUMNS(
SUMMARIZE(
'FactInternetSales'
,'Product Name'[EnglishProductName]
,'FactInternetSales'[OrderDate]
)
,"@PreviousDate"
, CALCULATE(
@Erik-H-zz
Erik-H-zz / ValueofPreviousDateSales.Dax
Created March 1, 2022 17:25
Get the value of the previous sales date
Value of Previous Date Sales =
VAR PreviousDate = [Previous Date of Sales]
RETURN
CALCULATE(
[Sum Amount]
,'FactInternetSales'[OrderDate] = PreviousDate
)
@Erik-H-zz
Erik-H-zz / DaysSinceLastSale.dax
Created March 1, 2022 17:27
The amount of days between the previous sale and the current one.
Days since last sale =
DATEDIFF(
[Previous Date of Sales]
, MIN(FactInternetSales[OrderDate])
, DAY
)