How to implement this query in Alteryx
Select
customerKey
,storeKey as primary_store FROM (
SELECT
customerKey
,storeKey
,sum(salesAmount) as aggsale
,ROW_NUMBER() OVER(PARTITION BY customerKey ORDER BY sum(salesAmount) DESC) as store_rank
FROM sampletable
where salesAmount > 0
and visitKey is not null
and customerKey in (2073,2083)
group by customerKey,storeKey
) A
WHERE store_rank = 1
Expected output
| customerKey | primary_store |
| 2073 | 14 |
| 2083 | 31 |
Sample Table
Book1.xlsx