diff --git a/services/dataProcessor.ts b/services/dataProcessor.ts index 1c9b84a..c8e3da5 100644 --- a/services/dataProcessor.ts +++ b/services/dataProcessor.ts @@ -239,12 +239,16 @@ const normalizeMonth = (rawMonth: string): string => { const getColumnValue = (row: any, aliases: string[]): string => { const rowKeys = Object.keys(row); const normalizedRowKeys: Record = {}; + rowKeys.forEach(k => { - normalizedRowKeys[k.trim().toLowerCase()] = k; + // Normalize by removing all non-alphanumeric characters for a bulletproof exact match + // e.g., "ACOS %" -> "acos", "Sales (30d)" -> "sales30d" + const cleanKey = k.toLowerCase().replace(/[^a-z0-9]/g, ''); + normalizedRowKeys[cleanKey] = k; }); for (const alias of aliases) { - const lookup = alias.trim().toLowerCase(); + const lookup = alias.toLowerCase().replace(/[^a-z0-9]/g, ''); if (normalizedRowKeys[lookup]) { const actualKey = normalizedRowKeys[lookup]; const val = row[actualKey];