fix: correct ad spend over-calculation in Weekly Grid

- Refactored mergeSalesAndAdsData to aggregate by ASIN+Customer+Year+Week
- Each ASIN/Week now produces exactly one output record
- Updated pivotWeeklySalesData to use ASIN as primary key
- Fixed double-counting when same ASIN had multiple SKUs
- Added support for ads-only records (ASINs with spend but no sales)
- Changed App.tsx to use filtered ads data for accurate totals
This commit is contained in:
Christian Vidal Wolf
2026-01-22 11:37:53 +01:00
parent 8b47ab844e
commit 17441a9b30
2 changed files with 109 additions and 77 deletions
+2 -2
View File
@@ -248,8 +248,8 @@ const App: React.FC = () => {
// Combine Sales & Ads Data dynamically based on current filters
const combinedAdsData = useMemo(() => {
return mergeSalesAndAdsData(filteredData, adsData);
}, [filteredData, adsData]);
return mergeSalesAndAdsData(filteredData, filteredAdsData);
}, [filteredData, filteredAdsData]);
// Derive Context Data (Product Line Context when drilling down)
const contextAggregatedData = useMemo(() => {