+ Reply to Thread
Results 1 to 8 of 8

SUMPRODUCT with comparing condition

  1. #1
    Registered User
    Join Date
    08-25-2015
    Location
    HCM
    MS-Off Ver
    2010
    Posts
    17

    SUMPRODUCT with comparing condition

    Hi pros,
    I have a table like this:

    Date1 Date2 Amount
    1 5 10
    2 3 15
    3 4 20

    and somewhere else, my Date0 = 4

    My calculation is total of all rows and each row is: (min ([Date0]+1,@[Date2]) - @[Date1]) x Amount. My expected result is 75, which is (4 x 10) + (1 x 15) + (1 x 20).
    May I do this calculation with just 1 SUMPRODUCT without supporting column?
    Need your help, thanks alot.
    Attached Files Attached Files
    Last edited by navafolk; 07-28-2020 at 09:59 PM.

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    81,698

    Re: SUMPRODUCT with comparing condition

    There are instructions at the top of the page explaining how to attach your sample workbook.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    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: SUMPRODUCT with comparing condition

    ...in addition since this is clearly a much simplified example and probably doesn't represent the size or layout of your actual data, we often find that when we give an answer to what is a trivial non representative example when the solution is used with the real world data it doesn't work because of factors like string length and other stuff which is important but hasn't been mentioned.

    Therefore upload your real workbook (or at least a cut down copy), and manually add the results you expect to see. Clearly identify which is original data and which are the results and in a note clearly explain how you have arrived at your results.
    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.

  4. #4
    Registered User
    Join Date
    08-25-2015
    Location
    HCM
    MS-Off Ver
    2010
    Posts
    17

    Re: SUMPRODUCT with comparing condition

    Quote Originally Posted by Richard Buttrey View Post
    ...in addition since this is clearly a much simplified example and probably doesn't represent the size or layout of your actual data, we often find that when we give an answer to what is a trivial non representative example when the solution is used with the real world data it doesn't work because of factors like string length and other stuff which is important but hasn't been mentioned.

    Therefore upload your real workbook (or at least a cut down copy), and manually add the results you expect to see. Clearly identify which is original data and which are the results and in a note clearly explain how you have arrived at your results.
    Thank you Mods Richard Buttrey and AliGW,
    I uploaded my sample excel file with some manual calculations and expected result. Hope for your helps.

  5. #5
    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: SUMPRODUCT with comparing condition

    I can't see any easy way using SumProduct just at the moment

    Why the reluctance to add a helper column the sum of which would give your anwer?

  6. #6
    Forum Guru Bo_Ry's Avatar
    Join Date
    09-10-2018
    Location
    Thailand
    MS-Off Ver
    MS 365
    Posts
    7,213

    Re: SUMPRODUCT with comparing condition

    Please try
    =SUM((IF(Table2[date2]>B2+1,B2+1,Table2[date2])-Table2[date1])*Table2[amount])
    Confirm by Ctrl+Shift+Enter

  7. #7
    Forum Guru samba_ravi's Avatar
    Join Date
    07-26-2011
    Location
    Hyderabad, India
    MS-Off Ver
    Excel 2021
    Posts
    8,915

    Re: SUMPRODUCT with comparing condition

    if you want to use sumproduct try below
    =SUMPRODUCT((((Table2[date2]<=Table1[Value]+1)*Table2[date2]+(Table2[date2]>Table1[Value]+1)*(Table1[Value]+1))-Table2[date1])*(Table2[amount]))
    Samba

    Say thanks to those who have helped you by clicking Add Reputation star.

  8. #8
    Registered User
    Join Date
    08-25-2015
    Location
    HCM
    MS-Off Ver
    2010
    Posts
    17

    Re: SUMPRODUCT with comparing condition

    Quote Originally Posted by samba_ravi View Post
    if you want to use sumproduct try below
    =SUMPRODUCT((((Table2[date2]<=Table1[Value]+1)*Table2[date2]+(Table2[date2]>Table1[Value]+1)*(Table1[Value]+1))-Table2[date1])*(Table2[amount]))
    Great, thanks Samba.
    Really smarter, prettier and shorter than what I though yesterday.
    =SUMPRODUCT(--(Table2[date2]<(Table1[Value]+1)),Table2[date2]-Table2[date1],Table2[amount])
    +SUMPRODUCT(--(Table2[date2]>=(Table1[Value]+1)),Table2[date2]-Table2[date1],Table2[amount])

+ 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. Comparing dates as IF condition (empty cell not recognized)
    By v2ikevaal in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-12-2015, 09:24 AM
  2. [SOLVED] Comparing dates with extra condition
    By Wayprof in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 11-09-2013, 12:25 PM
  3. Replies: 1
    Last Post: 05-19-2012, 02:54 AM
  4. SUMPRODUCT comparing two ranges
    By Steve_Courts in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-07-2010, 12:46 PM
  5. Comparing 2 Columns using SUMPRODUCT ONLY
    By meyero90 in forum Excel General
    Replies: 6
    Last Post: 08-19-2010, 08:48 AM
  6. Comparing figures over 6 months (SUMPRODUCT)
    By buffalobill in forum Excel General
    Replies: 4
    Last Post: 05-30-2010, 02:41 AM
  7. comparing two columns under specific condition- please help!
    By flutterby in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-02-2009, 06:17 PM

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