Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Partition Over Query in Alteryx

tjamal1
8 - Asteroid

 

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 

customerKeyprimary_store
207314
208331

 

Sample Table

Book1.xlsx

4 REPLIES 4
neilgallen
12 - Quasar

this is quite simple in alteryx. the attached workflow gets you there.

 

Capture.PNG

 

the first three filters are taking care of the 

 

FROM sampletable
where salesAmount > 0
and visitKey is not null
and customerKey in (2073,2083)

 

the summarize tool then calculates the sales amount total by customer key and store key. We then sort by those same dimensions and use the sample tool to extract the top row per group, which is where you're going with 

 

WHERE store_rank = 1
danilang
19 - Altair
19 - Altair

Hi @tjamal1 

 

Almost identical to @neilgallen's with the customerKey filtering at the end instead of at the beginning

 

WF.png

 

Dan 

tjamal1
8 - Asteroid

Thanks for the reply 
It helped 🙂
Have a good day !

tjamal1
8 - Asteroid

Thanks for the reply 

Both solution working for me 
It helped 🙂
Have a good day !

Labels