Alteryx Designer Desktop Discussions

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

How to create deciles using below approach (sql)

Vijay1102
6 - Meteoroid

Hi Folks,

 

I want to create custom decile for my project. Tile tool is not helping much in obtaining required results. I want to convert below sql code into Alteryx environment to get the appropriate deciles. Can anyone help me in this.

Thanks in advance!

(data attached for reference)

 

-- Code for Creating deciles

 

create or replace table identifier($tablef) as
with temp as (
select npi, count(distinct patient_id) as pats, count(distinct claim_id) as trx
from identifier($table2)
where npi is not null
group by 1
)
,
running as (
select *
, SUM(trx) OVER (ORDER BY trx DESC) as running_trx
, SUM(trx) OVER (ORDER BY trx DESC) / SUM(trx) OVER () as ratio
, 11 - ceil(10 * SUM(trx) OVER (ORDER BY trx DESC) / SUM(trx) OVER ()) as decile
from temp
)

8 REPLIES 8
BS_THE_ANALYST
14 - Magnetar

@Vijay1102 Are you looking for something like this?

BS_THE_ANALYST_0-1679668643687.png

It's been a while since I've dug through SQL.

 

Vijay1102
6 - Meteoroid

Thanks for pitching in but above sql code is creating deciles using a ratio factor which I need to crack. Your solution is simply splitting entire data into 10 splits regardless of sales column which is key for this deciling.

FinnCharlton
13 - Pulsar

@Vijay1102 , some sample data would be really useful in this case

 

Vijay1102
6 - Meteoroid

Data attached. TRx is as same as sales in demo.

FinnCharlton
13 - Pulsar

@Vijay1102 , this should match your SQL query. Cool way to do deciles, wouldn't have though of this.

FinnCharlton_0-1679670334873.png

 

Vijay1102
6 - Meteoroid

will implement this & get back to you. Thanks!

Vijay1102
6 - Meteoroid

Works flawlessly, Thanks again!

Vijay1102
6 - Meteoroid

Hi Finn,

 

Tried your solution & working to a large extend but I'm not able to get exact match. I tried to debug the possibilities but not through. Can you suggest where is the gap?

Thanks,

 

Vijay1102_0-1679926231770.png

 

Polls
We’re dying to get your help in determining what the new profile picture frame should be this Halloween. Cast your vote and help us haunt the Community with the best spooky character.
Don’t ghost us—pick your favorite now!
Labels