Product of Rows in a Column

Hello, I need to compute a running product in a column. This is similar to a running total, but instead I need to multiply the row values in a column and store the result of each row in a new column. I’ve uploaded an excel file with two sheets that demonstrates what I’m trying to accomplish.

Thanks!

rowproduct example.xlsx (10.6 KB)

Hello @hundredplanks and welcome to the Community!

EasyMorph doesn’t have the running product aggregation out of the box. However, it can be calculated using iterations, which is a bit advanced topic that requires some learning.

Simply speaking, iterations is a loop. It takes a table, and for each row of the table it runs another module in the same EasyMorph project. The other module performs calculations that need to be repeated as many time as many rows in the original table. Row data (such as Value in your example) can be passed to the iterated module via module parameters.

For a running product, we also need to pass the result of previous multiplication from row to row. Which means that we need to create a temporary file that will accumulate the result of running product.

Before such recursive iteration, the initial value of the running product should be set to 1, so we create a temporary file with that value. In the iterated module we read the accumulated product from the temporary file, multiply it by the given row value, and save the product back to the same file so that it can be passed to the next row.

Finally, we append the column with running product to the original dataset using the “Append table” action in the “Append columns” mode.

See below the example the does the described above.

running-product.morph (6.1 KB)

It may sound a bit complicated, but it actually took me longer to write this post than to design the example.

Thanks for your help! I was able to apply your solution to my project and I learned a powerful new technique along the way.

:raised_hands:

You’re welcome! :slight_smile: