diversification
New Member
- Joined
- Jun 24, 2020
- Messages
- 37
- Office Version
- 365
- Platform
- Windows
^ This is an example of the data I'm using. In reality, Sheet1 is ~30,000 Rows deep, and Sheet2 is ~800 Rows deep.
What I'm trying to accomplish:
- Table1 (in Sheet1) is the raw data showing a ton of Account#s with the Symbols they hold, and for each Symbol, it breaks out the purchase lots across multiple rows, and specifies whether each lot has an Unrealized Gain or Loss associated with it.
- Table 2 (in Sheet2) has a greatly reduced subset of the same Account#s and Symbols in Table1. Each unlike in Table1 which has the same Account# & Symbol combination appearing in multiple rows, each combination of Account# and Symbol only appears in one single row in Sheet2.
- For each row in Table2, I want the following:
- Match the Account# and Symbol to all occurrences in Table1
- For all matches, sum separately the Short Unrealized Gain or Loss and the Long Unrealized Gain or Loss
- In a new column in Sheet2, combine the following items: (1) The Symbol from that row (2) The Value from that row (3) The aforementioned summed Short Unrealized Gain or Loss (4) The aforementioned summed Long Unrealized Gain or Loss
My Steps:
- In Table1, Column V, I create a column titled "Acct, Ticker, L/S" which combines the Account #, the Symbol, and the type of Unrealized Gain (Long or Short) into one cell using the following formula:
Excel Formula:
= TEXT(TEXTJOIN(", ", TRUE,TRIM([@[Account '#]]), TRIM([@Symbol]), TRIM([@[Short or Long Term]])),)
- In Sheet1, Column Z, outside of Table1, I created a column titled "Unique Acct, Ticker, L/S". This column isolates the unique values from the "Acct, Ticker, L/S" column from Step 1 (you'll recall that I said in Table1, there are multiple occurrences of the same combination of Account #, Symbol, and the 'Long' or 'Short' designation.
Excel Formula:
=UNIQUE(Table1[Acct, Ticker, L/S])
- In Sheet1, Column AA, outside of Table1, I created a column titled "G/L Total". Using the neighboring cell in Column Z (Step 2 - "Unique Acct, Ticker, L/S") this formula looks for matches in Column V (Step 1 - "Acct, Ticker, L/S") and sums the Unrealized Gain or Loss from Table1[Unrealized Gain Loss] (Column P).
Excel Formula:
=SUMIF(Table1[Acct, Ticker, L/S],@Z:Z,Table1[Unrealized Gain Loss])
- In Table2, Column M, I created a column titled "Unrealized Short G/L" looks at the Table2[Account Number], Table2[Symbol] and uses the following formula to pull in the associated "G/L Total" (Step 3 - Sheet1, Column AA) from Sheet1.
Excel Formula:
=INDEX(Sheet1!$AA:$AA, MATCH((TRIM([@[Account Number]])&", "&TRIM([@Symbol])&", Short"),Sheet1!$Z:$Z, 0))
- In Table2, Column N, I created a column titled "Unrealized Long G/L" and did the same exact thing as in Step 4, except this time it looks for "Long" instead of "Short." =INDEX(Sheet1!$AA:$AA, MATCH((TRIM([@[Account Number]])&", "&TRIM([@Symbol])&", Long"),Sheet1!$Z:$Z, 0))
Excel Formula:
=INDEX(Sheet1!$AA:$AA, MATCH((TRIM([@[Account Number]])&", "&TRIM([@Symbol])&", Long"),Sheet1!$Z:$Z, 0))
- In Table2, Column P ("Symbol, Val, G/L"), for each row, I combine the corresponding values from columns F, H, M, N ("Symbol", "Value", "Unrealized Short G/L", "Unrealized Long G/L"). This gives me what I wanted.
Excel Formula:
=[@Symbol]&" -- Current Value: "&TEXT([@Value],"$#,##0;($#,##0)")&", Short: "&IFERROR(TEXT([@[Unrealized Short G/L]],"$#,##0;($#,##0)"),TEXT(0,"$0"))&", Long: "&IFERROR(TEXT([@[Unrealized Long G/L]],"$#,##0;($#,##0)"),TEXT(0,"$0"))
QUESTION:
Is there a better, more efficient, and less resource-intensive way to find the unique values in Step 2 WITHOUT a macro / VBA code? I don't understand that stuff well, so if it breaks I'm going to be back here trying to get troubleshooting help, and that could cause too much of a delay for something I already have working (albeit slowly.) I'm guessing the reason this particular formula slows down the sheet so much is because it's having to check each of the ~30,000 cells in the column against the already-found unique values, which obviously is a ton of work. I'd also like to avoid doing it manually using the "eliminated duplicates" button or whatever it is.