Advent of Code is back! Unwrap daily challenges to sharpen your Alteryx skills and earn badges along the way! Learn more now.
Free Trial

Alteryx Designer Desktop Discussions

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

Updating / Inserting records

AlterIT
8 - Asteroid

I am trying to insert/update records into a table using insert/update logic.

 

Background: Base table has customer records for each state and all of them have a rank within the state. I am trying to insert new customer records to each state with a rank higher than maximum rank within each state or move customer from one state to another with the same rank logic.

 

As you could see, when customer 101 moves from OH to CA it got rank 1 since CA does not have any records, at the same time when another customer (201) got added to CA it got rank 2 since rank 1 is already occupied by customer 101. 

 

Similarly for customer 112, it got added to OH and since its max rank is 10, this new customer will get a rank of 11 and so on.

 

What I tried: I have designated customer ID as primary key in the base table and tried to load the Update/Insert records using insert/update logic. However, I am unable to find a logic to get the Rank working. I have attached the data file I am using as well. Thank you

 

Base Table

Customer IDStateRegionRankRevenueMarginProfit
101OHEast1140010140
102OHEast2125015188
103OHEast35008400
104OHEast4600840
105OHEast590012100
106OHEast68501580
107OHEast7700010700
108OHEast86300201200
109OHEast9330012300
110OHEast10310011320

 

Update/Insert Records

Customer IDStateRegion
101CAWest
201CAWest
112OHEast

 

Desired State (Expected Output)

Customer IDStateRegionRankRevenueMarginProfitComment
102OHEast2125015188 
103OHEast35008400 
104OHEast4600840 
105OHEast590012100 
106OHEast68501580 
107OHEast7700010700 
108OHEast86300201200 
109OHEast9330012300 
110OHEast10310011320 
112OHEast11   New Customer added to  OH
101CAWest1140010140Customer moved from OH to CA
201CAWest2   New Customer added to CA
1 REPLY 1
Yoshiro_Fujimori
15 - Aurora

@AlterIT ,

I hope this works for your case.

Yoshiro_Fujimori_0-1678149414207.png

 

Labels
Top Solution Authors