Alteryx Designer Desktop Discussions

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

Multiplying records, similar to Sum in Summarize tool

Afrooz
7 - Meteor

Hi everyone

 

I am trying to Multiply one column values together similar to sum in summarize tool. 

for example. [Field] = 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 and I want to multiply them together. 

would be great if someone could help me with this. 

 

 

 

Thanks

Afrooz

14 REPLIES 14
ponraj
13 - Pulsar

Here is the sample workflow. Hope this is helpful. 

 

Capture.PNG

Afrooz
7 - Meteor

Hi @ponraj

 

Thanks for your solution. 

I need to group by date column and ID so I need to to have the result of the multiplication to be a column and not only one records. this workflow gives me only one record.

 

 

Many thanks

Afrooz

ponraj
13 - Pulsar

Possible to share sample data and output? 

neilgallen
12 - Quasar

On a mobile so unable to mock up a workflow but....

 

add a tile tool set to unique value, with your grouping fields as the unique values. To be safe, check the “leave unsorted” option. 

the tile field will create two new fields, one tile number and one sequence. This becomes important later. 

then use a multi row formula tool. Check the fields you want as your grouping (or use the newly created tile number). Set Missing rows to be null. 

your formula would be something like (excuse the syntax):

 

if isnull([row-1:field]) then 1*[row 0: field] else [row-1:new field]*[row 0: field] endif

 

then sort on your tile number, ascending and tile sequence number descending. 

a sample tool will let you choose a grouping field and take the first row per group. This is done in case your values have a negative. 

i *think* that gets you there. 

Afrooz
7 - Meteor

Hi @neilgallen 

 

Thanks for your response. 

I'm not sure which part I'm doing wrong but it doesn't give me the answer. 

would be great if you could give me a sample workflow when you get a chance.

 

Many Thanks,

Afrooz

neilgallen
12 - Quasar

see attached example

Afrooz
7 - Meteor

Hi @neilgallen  

 

Thank you for the solution 

Since I'm very new in Alteryx, Would you be able to explain what the workflow does a bit for me please?

 

 

I really appreciate your help

 

Thanks

Afrooz

neilgallen
12 - Quasar

Sure thing..

 

This is built with five assumptions:

1) you want to do this across multiple groups

2) you may not know the number of values that you have to multiply

3) there may be negative values in the multiplied values

4) none of the rows have missing values

5) there may be fractional values less than one in the records.

 

The tile tool is creating two sets of record IDs. One for each group, and then a record ID within each group. This will be important later.

 

The multi-row formula tool is where we're actually doing the multiplication with 

 

IF ISNULL([Row-1:Field]) THEN 1*[Field] ELSE [Field]*[Row-1:MULT] ENDIF

 

 

We have the group by set on the grouping fields, and set values for rows that don't exist to null.

 

So, the first row in every group checks for "Row-1", which doesn't exist, and so the above setting says that value is null. Our formula checks and says then multiply 1 against the field value to keep it the same. this only really applies for the first row in our dataset. For every other row, look at the multiplication total in the row above and multiply it by the value in the current row.

 

At this point we sort the records by the tiled field we created earlier ([tile_num]) and then by the sub-record ID ([tile_sequencenum]). We're sorting the records by the sub-record ID descending to ensure that the last value is the first record we see. We're doing it this way because the sample tool used next doesn't have a "Last N records" option. Also we're doing this (instead of taking the maximum value in the grouping set) because it's possible that your records have negative values in it, or maybe fractional values less than one.

 

The sample tool used last then takes the first record per group so we have our summary of each multiplied value.

 

let me know if there's any questions.

Afrooz
7 - Meteor

Hi @neilgallen 

 

thanks for the explanation, it makes more sense now however I still not quiet sure about Tile and sample tools.

Also it still doesn't give me the correct result, 

the formula says if row-1 is null then 1* current Field, to get the current value in MULT column, but it changes the value for me, it doesn't return the exact same number and not sure why.

 

I also have many nulls in [Field] which is correct and I want those nulls to be null in the MULT column.

 

I'm sorry for asking many questions bu would be great if you could help me with this. 

 

 

Many Thanks

Afrooz

Labels