+ Reply to Thread
Results 1 to 8 of 8

sum(if( function where the argument logical_test contains arrays

Hybrid View

  1. #1
    Registered User
    Join Date
    02-17-2014
    Location
    São Paulo
    MS-Off Ver
    Excel 2007
    Posts
    5

    sum(if( function where the argument logical_test contains arrays

    Hi all,
    I'd like to add a new condition to the formula below, which is supposed to calculate the average trade price in a few deals.

    In English, this means that, if Selected Row's Date (B15) is less than or equal to today's date (B4), then do the following calculation. It's calculation trading results given (i) the security (cells HM$13), and (ii) the Settlement Date (cells $B15). I need to add the condition that Trade Date is different than the Settlement Date (both dates are in two different columns in another sheet, where each line displays one particular trade)

    =IF($B15<=$B$4;IF(BG15<>0;SUM(IF((SettlDate_Blotter=$B15)*(Securities_Blotter=HM$13);Contracts_Blotter*TradePrice_Blotter))/BG15;SUM(IF((SettlDate_Blotter=$B15)*(Securities_Blotter=HM$13);Contracts_Blotter*TradePrice_Blotter)));0)

    When Trade Date (shown as a column in sheet 2) = Settl. Date (shown as a different column in sheet 2), the calculation is exactly the one shown above. But when Trade Date is different than Settl. Date, the result should be brought to present value.


    Any ideas??

    Thanks in advance,
    Bruno

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: sum(if( function where the argument logical_test contains arrays

    Hi,

    Why aren't you using the AVERAGEIF() function, or if there are several if criteria the AVERAGEIFS() function? You save yourself the task of counting and summing.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    02-17-2014
    Location
    São Paulo
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: sum(if( function where the argument logical_test contains arrays

    Hi,
    I can't use the AVERAGEIFS() function, because the Average price is the weighted average of the prices traded in that date, weighted by the volume of each trade (number of contracts, displayed in the array "Contracts_Blotter"

  4. #4
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,679

    Re: sum(if( function where the argument logical_test contains arrays

    Quote Originally Posted by Bruno Amaral View Post
    When Trade Date (shown as a column in sheet 2) = Settl. Date (shown as a different column in sheet 2), the calculation is exactly the one shown above. But when Trade Date is different than Settl. Date, the result should be brought to present value.
    I'm not sure what that means, what is "present value" in the context of the values shown here?

    Try this formula to simplify your original

    =IF($B15<=$B$4;SUMPRODUCT((SettlDate_Blotter=$B15)*(Securities_Blotter=HM$13);Contracts_Blotter;TradePrice_Blotter)/IF(BG15=0;1;BG15);0)
    Audere est facere

  5. #5
    Registered User
    Join Date
    02-17-2014
    Location
    São Paulo
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: sum(if( function where the argument logical_test contains arrays

    Quote Originally Posted by daddylonglegs View Post
    I'm not sure what that means, what is "present value" in the context of the values shown here?

    Try this formula to simplify your original

    =IF($B15<=$B$4;SUMPRODUCT((SettlDate_Blotter=$B15)*(Securities_Blotter=HM$13);Contracts_Blotter;TradePrice_Blotter)/IF(BG15=0;1;BG15);0)

    Hi,
    Thanks for the simplified formula.
    By present value I meant that, in cases where SettleDate_Blotter is different than TradeDate_Blotter, that is, when the security is traded today, but only settled tomorrow, this result should be multiplied by [1/(1+ daily interest rate)].
    What I'm trying to figure out is a way of nesting this additional IF() function, which separates the lines in sheet 2 where the value in the vector TradeDate_Blotter is different than the one in the other vector, SettlDate_Blotter.
    Of course the IF() function demanding that $B15 equals SettlDate_Blotter should remain active.

    So, if $B15=SettlDate_Blotter, but SettlDate_Blotter is different than TradeDate_Blotter, the result should be multiplied by the discount factor. Otherwise, not.

    Not sure if I'm making myself clear enough. It's pretty hard for a non-native speaker.

    Many thanks in advance

  6. #6
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    Microsoft 365
    Posts
    14,679

    Re: sum(if( function where the argument logical_test contains arrays

    OK try this version

    =IF($B15<=$B$4;SUMPRODUCT((SettlDate_Blotter=$B15)*(Securities_Blotter=HM$13);Contracts_Blotter;TradePrice_Blotter;1/(1+daily interest rate*(SettlDate_Blotter<>TradeDate_Blotter))/IF(BG15=0;1;BG15);0)

  7. #7
    Registered User
    Join Date
    02-17-2014
    Location
    São Paulo
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: sum(if( function where the argument logical_test contains arrays

    Quote Originally Posted by daddylonglegs View Post
    OK try this version

    =IF($B15<=$B$4;SUMPRODUCT((SettlDate_Blotter=$B15)*(Securities_Blotter=HM$13);Contracts_Blotter;TradePrice_Blotter;1/(1+daily interest rate*(SettlDate_Blotter<>TradeDate_Blotter))/IF(BG15=0;1;BG15);0)
    The problem with the formula above is that it results in a #DIV/0! error, probably because of this factor:

    *(SettlDate_Blotter<>TradeDate_Blotter)

    Any idea why that is? The array SettlDate_Blotter is a column in sheet two, which contains only dates. They're the settlement date of each trade, shown in a table in sheet two (each line is a trade done). The array TradeDate_Blotter is another column of the same table, which shows the date when the deal was done.

  8. #8
    Registered User
    Join Date
    02-17-2014
    Location
    São Paulo
    MS-Off Ver
    Excel 2007
    Posts
    5

    Re: sum(if( function where the argument logical_test contains arrays

    sry, nevermind the last reply. something was wrong with my formula

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Unknown number of arrays as argument to VBA function
    By Huugin in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-03-2012, 05:30 PM
  2. IF function: Using text in logical_test with multiple variables and replacing with text
    By SarahRachelJones in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-25-2012, 02:17 PM
  3. [SOLVED] ByRef argument type mismatch / Passing array as a function argument
    By pzling in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-29-2012, 06:23 PM
  4. Writing Function with Arrays in Argument List
    By RGrunden in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-27-2012, 11:01 PM
  5. Function (array argument, range argument, string argument) vba
    By Witek in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-24-2005, 11:07 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1