Category Sales by Region

<#-- Assume reportData is the list passed from the script --> <#if reportData?? && reportData?has_content> <#-- Dynamically determine region columns (excluding CategoryName and TotalSales) --> <#assign firstRow = reportData[0]> <#assign regions = firstRow?keys?filter(k -> k != 'CategoryName' && k != 'TotalSales')?sort> <#-- Initialize column totals --> <#assign regionTotals = {} > <#list regions as region> <#assign regionTotals = regionTotals + {region: 0} > <#assign grandTotal = 0> <#list regions as region> <#list reportData as row> <#list regions as region> <#assign cellValue = (row[region]!0)> <#-- Update region total --> <#assign regionTotals = regionTotals + {region: regionTotals[region] + cellValue} > <#assign rowTotal = (row.TotalSales!0)> <#-- Update grand total --> <#assign grandTotal = grandTotal + rowTotal> <#list regions as region>
Category${region} Total Sales
${row.CategoryName!'N/A'}${cellValue?string("0.00")}${rowTotal?string("0.00")}
Total${(regionTotals[region])?string("0.00")} ${grandTotal?string("0.00")}
<#else>

No crosstab data available.