Get Inspire insights from former attendees in our AMA discussion thread on Inspire Buzz. ACEs and other community members are on call all week to answer!

Alteryx Designer Desktop Discussions

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

Multi Row Formula

cmohyi
7 - Meteor

Hi all,

 

I know that the Multi Row Forumla tool will (probably) solve my problem but I don't know how to get there. 

 

I have a list of stocks where some securities will have multiple line items and some might just have 1. There are many fields that differentiate them beyond a Shares column but I narrowed it down for simplicity. I have a column that has the number of shares I need to sell that's constant based off the Security name and I need to continuously subtract from the 2nd column. So for GOOGL, I want to sell a total of 85 shares, so I want to sell all 40 from the first entry, all 30 from the second entry, 15 from the third entry, and none from the last two. 

 

It's a bit confusing so I'm happy to give further clarification if needed. Thank you greatly for any help in figuring this out!

 

SecuritySharesShares to SellRemaining Shares to SellShares Remaining
AAPL5003000200
GOOGL4085450
GOOGL3085150
GOOGL10085085
GOOGL1085010
GOOGL58505
AMZN505550
AMZN105505
4 REPLIES 4
DavidP
17 - Castor
17 - Castor

I think your problem is essentially a variation on the FIFO (first in first out) principle. When you're selling stocks, you want to sell from the oldest batches first.

 

There are 2 ways to solve this problem.

 

1. Build an iterative macro

2. Split sales and purchases into rows with quantity of 1 and then use the date for each to ensure that every sales transaction uses the oldest purchases first.

 

There is a previous post on the community that deals with a similar problem. I used the 2nd method. Here is the link to that post.

 

https://community.alteryx.com/t5/Alteryx-Designer-Discussions/FIFO-Calculation-with-multiple-product...

 

If the solution in that post is similar to what you're looking to achieve, I'll be happy to help you convert the solution based on your data. Let me know.

cmohyi
7 - Meteor

Thanks David!

 

That post is definitely as close as I've seen to what I'm trying to figure out but mine differs in two ways. For one, these are all holdings, not transactions, so I don't need to differentiate buys and sells. Also I'm not using FIFO but more likely LIFO since I want to sell the highest cost (and generally more recently purchased) shares first. 

 

I like your solution in that other post a lot, and I'm hoping to get something similar. But the more I try to get a solution, the more it looks like a macro will be necessary. 

DavidP
17 - Castor
17 - Castor

Hi @cmohyi 

 

I've adapted the workflow for your purposes. Please see below. Let me know if this is what you're looking for and if you have any questions.

 

DavidP_0-1595969791285.png

 

 

cmohyi
7 - Meteor

@DavidP this is perfect! Thank you so much!!

Labels