Alteryx Designer Desktop Discussions

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

I need a vlookup macro in Alteryx to solve an iteration lookup issue

Suppu
7 - Meteor

Hello,

I need to keep iterating and lookup values in the same two columns unless I get and N/A . How do I do it ?
In the below example I kept on with lookups. If the result of vlookup is 0 then stop  or N/A. Please help.

Row LabelsSUMVLKUP1VLKUP2VLKUP3STOP
0 #N/A#N/A#N/A#N/A
152 0#N/A#N/A#N/A
981 0#N/A#N/A#N/A
9820.50#N/A#N/A#N/A
98230.250#N/A#N/A#N/A
329431044331520#N/A
32945111520#N/A#N/A
4433 1520#N/A#N/A
(blank) #N/A#N/A#N/A#N/A

 

After that I need to collate all the values in the above sample for 152 to get all the value in SUM column that corrspond.

32943 is related to 4433. Next iteration 4433 is related to 152. Similarly we get 152 for 32945. So we we add them to get SUM for 152.

While other values such as 981,982 remain as is with no iterations as they hit 0 in first round.
Please help .

9 REPLIES 9
caltang
17 - Castor
17 - Castor

It's very confusing to understand what you're asking... can you simplify the question and requirements?

 

Based on your data, I would say it would be good to Transpose your columns into rows by grouping them with a RecordID and Row Labels. You can use a few tools to get what you what, like a Multi-Row tool etc. without the need of iterative macro in this case (I believe, based on the information provided).

Calvin Tang
Alteryx ACE
https://www.linkedin.com/in/calvintangkw/
Suppu
7 - Meteor

Hello,

Below is a simplified version of my request.  I simply want to get total values for D . This is based on raw data I make a pivot table and then lookup values from the raw data to get related values . Please suggest.

Post Pivot Lookup Table :

Row LabelsSUMVLKUP1VLKUP2VLKUP3STOP
0 #N/A#N/A#N/A#N/A
D 0#N/A#N/A#N/A
E 0#N/A#N/A#N/A
F0.50#N/A#N/A#N/A
G0.250#N/A#N/A#N/A
A10BD0#N/A
C11D0#N/A#N/A
B D0#N/A#N/A
(blank) #N/A#N/A#N/A#N/A

Sample Raw Data:

CHILDPARENTSUM
IA2
IA2
IA1
KE0.5
KF0.25
GC3
GC2
GC2
GC2
GC1
GC2
GC1
AndrewDMerrill
13 - Pulsar

This is still somewhat unclear. The issues that still aren't clear for me:

1. Why does your Sample Raw Data has multiple duplicated child parent records with different [SUM]'s?

2. What is your vLookup on? Your Sample Raw Data has nothing in common with your Pivot Lookup Table? Would you post what the Pivot Lookup Table would look like if only using the Sample Raw Data that you included?

3. How is [SUM] calculated in the Pivot Lookup Table?

 

For this kind of problem it would be tremendously helpful to have Sample Input (like the raw data you included already), the Expected Output (for that Sample Input), and maybe even a step by step description for how one of the rows in the output was calculated.

 

The Iterative Lookup bit sounds to me like a variation of this weekly challenge: https://community.alteryx.com/t5/Weekly-Challenge/Challenge-12-Creating-an-HR-Hierarchy/td-p/36740

 

 

Suppu
7 - Meteor


Hi 
@AndrewDMerrill ,All

 

The post data has been made using excel but I want to use Alteryx and automate

I am doing a pivot on the raw data . So duplicates in parent child are summed. Sample after just Pivot :

Row LabelsSUM
0 
D 
E 
F0.5
G0.25
A10
C11
B 

 

Next the Row labels marked  I do a vlookup and continue to do until I get an N/A as there can be mutiple child-parent even after the pivot. After 1st iteration I get :

VLKUP1
#N/A
0
0
0
0
B
D
D

Next iteration and so on :

VLKUP2
#N/A
#N/A
#N/A
#N/A
#N/A
D
0
0

I need to write a macro of some sort so that it keeps iterating until it gets a 0 or N/A . If we hit N/A the macro stops for that row.
Imagine the raw data having mutiple hierarchies within the 2 columns child and parent and I need to calculate the overall total sum for a child parent . In the example value D which we get by A->B->D. After I know all the underlying sub hierarchies I will add the corresponding values to get the SUM. Please revert with questions.
In my previous post see the tables I want to create the vlookup columns via Alteryx 

CHILDPARENTSUM
IA2
IA2
IA1
KE0.5
KF0.25
GC3
GC2
GC2
GC2
GC1
GC2
GC1
AndrewDMerrill
13 - Pulsar

I understand the iterative process, but I still don't understand where the relationships are coming from.

You said that duplicates in parent-child are summed, this implies that using the Sample Raw Data you included above, step 1 (removing duplicates through aggregation) would result in:

ChildParentSum
IA5
KE0.5
KF0.25
GC13

 

^Is this correct?

 

Step 2 (Generate Row Labels where [Sum] is allocated to Parent):

Row LabelSum
A5
E0.5
F0.25
C13
I 
K 
G 

 

^Is this correct?

 

Step 3 (Perform Iterative Lookups from Parent to Child):

Row LabelSumVLKUP1STOP
A5In/a
E0.5Kn/a
F0.25Kn/a
C13Gn/a
I n/an/a
K n/an/a
G n/an/a

 

Finally, you mention performing some kind of summation based on the result of VLKUP columns, but I don't understand what that's supposed to look like. If all of this is what you're looking for, please add the result of that final summation step. Otherwise, please correct. What I have included above would be a very helpful form of clarification from you so that you can get the help that you are looking for. Please be a specific and simple as you can because we don't have the data or understanding of the problem that you do. I don't to steer you in the wrong direction because I misunderstood what it was that you are trying to accomplish.

Suppu
7 - Meteor

Hello,

I am trying with a mock up data . Below is a raw data :

 

CHILDPARENT

SUM

IA2
IA2
IA1
KE0.5
KF0.25
AD3
AD2
AD2
AD2
AD1
EG2
GC1

 

This is after pivot :
Row Labels        Sum of SUM

A5
C1
D10
E0.5
F0.25
G2

 

After first round of vlookup :

Iteration 1
D
#N/A
#N/A
G
#N/A
C

This is after second round of iteration :

Iteration 2
#N/A
#N/A
#N/A
#N/A
#N/A
#N/A

Since we hit N/A we stop. Meanwhile Iteration 1 Sum values are added to the earlier parent to get total value.

The requirement of mutiple vlookup is that parent can be a child of some other value . So it becomes the new parent and the sum values are transferred are added to the new parent and so on unless there is nothing to lookup to.

 

AndrewDMerrill
13 - Pulsar

In the data you provided above, you have the case where a child "K" has multiple parents "E" & "F". How would this be handled since vLookup typically only returns single value?

 

everything else is very helpful, and I think it has cleared up a lot for me! Thank you.

Suppu
7 - Meteor

Hello @AndrewDMerrill ,

 

Good catch !! In actual data there will not be any scenario like that . It will mapped to one value.
Please help me .

Edited the table :

CHILDPARENT

SUM

IA2
IA2
IA1
KM0.5
MO0.25
AD3
AD2
AD2
AD2
AD1
OG2
GC1
AndrewDMerrill
13 - Pulsar

This needs to be check, but its a least a start. Here is a sample based on my understanding of the problem statement. Please verify thoroughly as I'm not sure if I performed the sum correctly:

Main Workflow:

_Main.png

Iterative Macro (vLookups):

_Macro.png

Labels