From 5e8afa48fcf3ac9f0b6983a4ee0ef69eab53b10f Mon Sep 17 00:00:00 2001 From: dfinke Date: Fri, 11 Nov 2022 09:38:56 -0500 Subject: [PATCH] Add a Sales Data example, known data and diff criteria in the COUNTIF --- Examples/Tables/SalesData-WithTotalRow.ps1 | 28 ++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Examples/Tables/SalesData-WithTotalRow.ps1 diff --git a/Examples/Tables/SalesData-WithTotalRow.ps1 b/Examples/Tables/SalesData-WithTotalRow.ps1 new file mode 100644 index 0000000..24f18c0 --- /dev/null +++ b/Examples/Tables/SalesData-WithTotalRow.ps1 @@ -0,0 +1,28 @@ +try { Import-Module $PSScriptRoot\..\..\ImportExcel.psd1 } catch { throw ; return } + +$data = ConvertFrom-Csv @" +OrderId,Category,Sales,Quantity,Discount +1,Cosmetics,744.01,07,0.7 +2,Grocery,349.13,25,0.3 +3,Apparels,535.11,88,0.2 +4,Electronics,524.69,60,0.1 +5,Electronics,439.10,41,0.0 +6,Apparels,56.84,54,0.8 +7,Electronics,326.66,97,0.7 +8,Cosmetics,17.25,74,0.6 +9,Grocery,199.96,39,0.4 +10,Grocery,731.77,20,0.3 +"@ + +$xlfile = "$PSScriptRoot\TotalsRow.xlsx" +Remove-Item $xlfile -ErrorAction SilentlyContinue + +$TotalSettings = @{ + Quantity = 'Sum' + Category = @{ + # Count the number of categories not equal to Electronics + Custom = '=COUNTIF([Category],"<>Electronics")' + } +} + +$data | Export-Excel -Path $xlfile -TableName Sales -TableStyle Medium10 -TotalSettings $TotalSettings -AutoSize -Show \ No newline at end of file