From f0f58f84a04e6948f13e36335d142140266c6a57 Mon Sep 17 00:00:00 2001 From: dfinke Date: Mon, 10 Dec 2018 15:16:11 -0500 Subject: [PATCH] Added Timestamp Bucket example --- Examples/Grouping/TimestampBucket.ps1 | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Examples/Grouping/TimestampBucket.ps1 diff --git a/Examples/Grouping/TimestampBucket.ps1 b/Examples/Grouping/TimestampBucket.ps1 new file mode 100644 index 0000000..7acb421 --- /dev/null +++ b/Examples/Grouping/TimestampBucket.ps1 @@ -0,0 +1,39 @@ +$data = ConvertFrom-Csv @" +Timestamp,Tenant +10/29/2018 3:00:00.123,1 +10/29/2018 3:00:10.456,1 +10/29/2018 3:01:20.389,1 +10/29/2018 3:00:30.222,1 +10/29/2018 3:00:40.143,1 +10/29/2018 3:00:50.809,1 +10/29/2018 3:01:00.193,1 +10/29/2018 3:01:10.555,1 +10/29/2018 3:01:20.739,1 +10/29/2018 3:01:30.912,1 +10/29/2018 3:01:40.989,1 +10/29/2018 3:01:50.545,1 +10/29/2018 3:02:00.999,1 +"@ | Select-Object @{n = 'Timestamp'; e = {get-date $_.timestamp}}, tenant, @{n = 'Bucket'; e = { - (get-date $_.timestamp).Second % 30}} + +$f = "$env:temp\pivottest.xlsx" +Remove-Item $f -ErrorAction SilentlyContinue + +$pivotDefParams = @{ + PivotTableName = 'Timestamp Buckets' + PivotRows = @('Timestamp', 'Tenant') + PivotData = @{'Bucket' = 'count'} + GroupDateRow = 'TimeStamp' + GroupDatePart = @('Hours', 'Minutes') + Activate = $true +} + +$excelParams = @{ + PivotTableDefinition = New-PivotTableDefinition @pivotDefParams + Path = $f + WorkSheetname = "Log Data" + AutoSize = $true + AutoFilter = $true + Show = $true +} + +$data | Export-Excel @excelParams \ No newline at end of file