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

Alteryx Designer Desktop Discussions

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

assign a value to a constant in a workflow

chbarz
6 - Meteoroid

Hello everybody!

 

As I am new to Alteryx please be so kind and correct me in cases of abusing the "usual alteryx notation".

 

My question is the following one:

How can I assign a value, which I computed in a workflow to a "global variable" or constant in order to use it in the workflow again?

Toy-Example:

Given the following table:

AB
14
25
36

Workflow :

1) Compute the mean of A,

    For example this could be solved using the in-buildt summarize tool

 

2) Store the mean of A in a "global variable", e.g. avg_A:=mean(A)

 

3) substract avg_A from each entry of the column B

    For example this can be done by the in-buildt formula-tool

 

The "Pseudo-code" for this Toy example would look like :

 

#Assume A, B are simply vectors and not a matrix and A[i] denotes the i-th row/component of A

#1stdeclare a variable/constant
var mean_A=0;

#2nd compute the mean of the values of A
for(i=1,length(A),i++)
{
mean_A=mean_A+ A[i];
}
mean_A=mean_A / lenght(A);

#3rd substract mean_A from each component of B
for(i=1;length(B),i++)
{
B[i]=B[i]-mean_A;
}
4 REPLIES 4
jarrod
ACE Emeritus
ACE Emeritus
There aren't "global" variables like in regular code, however you can take the output from the summarize tool and append that avg_colA (or whichever fields you want to apply to the entire set). Then you can reference those fields in a formula tool. After you are done, you can just deselect they fields using a select tool.
chbarz
6 - Meteoroid

Thank you jarrod for your answer!

 

Unfortunately I do not know how to append the value "avg_colA" to the entire set.

 

 


Maybe therefore it is worthful going back to the toy example : (especially also to check, if I understood you correct)

 

Input : 

AB
12
23
34

 

Using the summary tool we get a "table" looking like

recordAVG_A
12=avg_colA

 

(here I explicitly wrote an equation to have on the one hand a numeric example and on the other hand to clearify the notation, i.e. AVG_A is the column/field name, avg_colA is the value)

 

Now I am looking for an Alteryx-solution to produce

The output:

ABAVG_A
12avg_colA
23avg_colA
34avg_colA

 

More precisely my problems are the following:

There is the Generate-Rows tool, which could create a such column AVG_A.

Then (using the record-id for example) I could join the column AVG_A with the Input table and obtain The output.

 

But for the Generate-Row tool I would need to know, the length of the original table.

Of course in the toy example the length is 3, but in a workflow it might vary.

 

Hence 2nd question: Is there a function, which determines the lenght of a table?

 

 

jarrod
ACE Emeritus
ACE Emeritus

I see. there is a simpler solution to what you are trying to do. you are using the join tool as an append. That would require you to know the number of records to append all avg_A records to the original set. 

 

instead of join, use the Append Fields tool where the original set is the "T" (target) and the summarized Avg_A stream is the "S" (Source).

 

I've attached an example workflow (in 2018.2 version).

chbarz
6 - Meteoroid

Thanks again jarrod!

 

 

Labels