# 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>

Category <#list regions as region> | ${region} | Total Sales
--- | --- | ---
<#list reportData as row>
${row.CategoryName!'N/A'} <#list regions as region> <#assign cellValue = (row[region]!0)> | ${cellValue?string("0.00")} <#-- Update region total --> <#assign regionTotals = regionTotals + {region: regionTotals[region] + cellValue} > <#assign rowTotal = (row.TotalSales!0)> | ${rowTotal?string("0.00")} <#-- Update grand total --> <#assign grandTotal = grandTotal + rowTotal>
Total <#list regions as region> | ${(regionTotals[region])?string("0.00")} | ${grandTotal?string("0.00")}

<#else>

No crosstab data available.