Complex SUMPRODUCT with Date Conditions

XcelRookie

New Member
Joined
Sep 5, 2017
Messages
5
Excel%20File.jpg
I've been unsuccessful in creating a formula that will deliver the calculated results that I've described below. Hoping someone can help.
I've tried using SUMIF and SUMPRODUCT - maybe there's another function better suited to the task? I'm trying to get a calculation, for each day, for the combined total of realized and unrealized profits for a complete portfolio of numerous stocks. I'm using Excel 2016. To view the sample worksheet, please see the file in the attached URL. What I'm trying to do is to get a calculation, for each day, for the combined total of realized and unrealized profits for a complete portfolio of numerous stocks. I'm using Excel 2016. Here's my attempt to articulate all the formula arguments:

STEP 1 - CALC THE UNREALIZED PROFITS

1. IF QUERY DATE => ENTRY DATE AND IF THE QUERY DATE IS<exit date="" or="" exit="" is="" blank,="" then="" calc="" the="" unrealized="" profit="" as="" of="" query="" by="" taking="" entry="" price="" and="" subtracting="" it="" from="" mtm="" (mark="" to="" market)="" multiply="" that="" sum="" #="" shares.="" return="" an="" error="" if="" required="" blank.
2. IF QUERY DATE< ENTRY DATE THEN SKIP THOSE LINES.

STEP 2 - CALC THE REALIZED PROFITS
1. IF QUERY DATE => ENTRY DATE AND IF THE QUERY DATE IS =>EXIT DATE, THEN PICKUP THE CORRESPONDING VALUES IN THE REALIZED PROFIT COLUMN AND SUM THOSE. (IN THIS CASE, NO NEED TO RETURN AN ERROR IF MTM PRICE IS BLANK WHICH IT MAY OR MAY NOT BE).2. AGAIN, IF QUERY DATE< ENTRY DATE THEN SKIP THOSE LINES.

STEP 3 - SUM THE RESULTS OF THE CALCS FOR UNREALIZED AND REALIZED PROFITS INTO A SINGLE OUTPUT VALUE

Clarification Notes:
1. Note that I've added the Result Calculation Columns K & L just for illustration purposes, all those calcs are intended to take place in the cells above the Query Dates.2. Values associated with Entry Dates that are > than the Query Date are never to be considered in these calculation.
3. Realized profit included above is driven off of fields that weren't included in this sample (so don't try to make sense of them).
*Sometimes (like in cell J12) there will be values in the MTM Price column even if the trade has been exited - I assume that those values will not cause any problems for the above calcs .

HOPE THIS MAKES SENSE - ANY HELP OR SUGGESTIONS GREATLY APPRECIATED!</exit>
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I've discovered that the link that I've created for this file through a Dropbox URL is not accessible. Will re-post with a capture of worksheet from Excel Jeanie.
 
Upvote 0
SUMPRODUCT to Calculate Multiple Products and Sums with Date Conditions

I've been unsuccessful in creating a formula that will deliver the calculated results that I've described below. Hoping someone can help.
I've tried using SUMIF and SUMPRODUCT - maybe there's another function better suited to the task? I'm trying to get a calculation, for each day, for the combined total of realized and unrealized profits for a complete portfolio of numerous stocks. I'm using Excel 2016. Here's a screenshot of my worksheet along with my attempt to articulate all the formula arguments:

ABCDEFGHIJKLM
1
2$495.00$505.00RESULT OF QUERYRESULT OF QUERY
3RealizedQuery Dates25-Aug-1730-Aug-1725-Aug-1730-Aug-17
4 Stock NameEntry DateEntry PriceExit Date# of SharesProfitMTM PRICEMTM PRICE
5 ABC Co.9-Aug-17$10.00100 $ 11.00 $ 10.25 $ 100.00 $ 25.00
6 Ma & Pa Co.10-Aug-17$10.008/17/201710010 $ 10.00 $ 10.00
7 XYZ Co.12-Aug-17$10.00100 $ 10.50 $ 11.00 $ 50.00 $ 100.00
8 Stardust Co.13-Aug-17$10.00100 $ 10.25 $ 11.25 $ 25.00 $ 125.00
9 New Co.14-Aug-17$10.008/25/2017100135 $ 135.00 $ 135.00
10 Startup Co.15-Aug-17$10.008/26/201710060 $ 12.25 $ 225.00 $ 60.00
11 Carparts Co.16-Aug-17$10.00100$ 9.00 $ 10.50 $ (100.00) $ 50.00
12 Food Co.17-Aug-17$10.008/28/2017100100 $ 10.50 $ 10.25 * $ 50.00 $ 100.00
13 Mining Co.30-Aug-17$10.00100 $ 9.00 $ (100.00)
14 $ 495.00 $ 505.00

<tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4

STEP 1 - CALC THE UNREALIZED PROFITS
1.IF QUERY DATE => ENTRY DATE AND IF THE QUERY DATE IS<exit date="" or="" exit="" is="" blank,="" then="" calc="" the="" unrealized="" profit="" as="" of="" query="" by="" taking="" entry="" price="" and="" subtracting="" it="" from="" mtm="" (mark="" to="" market)="" multiply="" that="" sum="" #="" shares.="" return="" an="" error="" if="" blank.
< EXIT DATE OR EXIT DATE IS BLANK, THEN CALC THE UNREALIZED PROFIT AS OF THE QUERY DATE BY TAKING THE ENTRY PRICE AND SUBTRACTING IT FROM THE MTM (MARK TO MARKET) PRICE AND THEN MULTIPLY THAT SUM BY THE # OF SHARES. RETURN AN ERROR IF THE MTM PRICE IS BLANK.
2.IF QUERY DATE< ENTRY DATE THEN SKIP THOSE LINES.
PERFORM THIS OPERATION FOR EACH ROW IN EACH COLUMN AND SUM ALL THE RESULTS

STEP 2 - CALC THE REALIZED PROFITS
1. IF QUERY DATE => ENTRY DATE AND IF THE QUERY DATE IS =>EXIT DATE, THEN PICKUP THE CORRESPONDING VALUES IN THE REALIZED PROFIT COLUMN AND SUM THOSE. (IN THIS CASE, NO NEED TO RETURN AN ERROR IF MTM PRICE IS BLANK WHICH IT MAY OR MAY NOT BE).
2. AGAIN, IF QUERY DATE< ENTRY DATE THEN SKIP THOSE LINES.
PERFORM THIS OPERATION FOR EACH ROW IN EACH COLUMN AND SUM ALL THE RESULTS

STEP 3 - SUM THE RESULTS OF THE CALCS FOR UNREALIZED AND REALIZED PROFITS (STEPS 1 & 2 ABOVE) INTO A SINGLE OUTPUT VALUE

Clarification Notes:
1. Query dates are highlighted in yellow.
2. Note that I've added the Result Calculation Columns L & M just for illustration purposes, all those calcs are intended to take place in the cells above the Query Dates.
3. Values associated with Entry Dates that are > than the Query Date are never to be considered in these calculation.

4. Realized profit included above is driven off of fields that weren't included in this sample (so don't try to make sense of them).
*Sometimes (like in cell J12) there will be values in the MTM Price column even if the trade has been exited - I assume that those values will not cause any problems for the above calcs .

Hope this makes sense - any help or suggestions greatly appreciated!</exit>
 
Upvote 0

Forum statistics

Threads
1,215,943
Messages
6,127,820
Members
449,409
Latest member
katiecolorado

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top