+ Reply to Thread
Results 1 to 15 of 15

Want formula

  1. #1
    Registered User
    Join Date
    06-01-2022
    Location
    UK
    MS-Off Ver
    2021
    Posts
    16

    Want formula

    Hi,

    I have values in Column B from Cell B3 onward. The differences of these values are in column C from cell C4 onward. In cell H4, I have a reference value with respect to which I want to find sum of differences.
    Attached Files Attached Files
    Last edited by Ali2356; 06-15-2022 at 01:18 AM.

  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. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: Want formula to find sum of differences of values >= or <= than a reference value

    I really don't understand your expected results!

    These do what you appear to be describing, but do not produce your expected results, so you have a bit more explaining to do:

    =SUMPRODUCT(($B$3:$B$27>=$H$4)*(ROW($B$3:$B$27)>=$E$4)*(ROW($B$3:$B$27)<=$F$4)*($C$3:$C$27>0),$C$3:$C$27)

    =SUMPRODUCT(($B$3:$B$27>=$H$4)*(ROW($B$3:$B$27)>=$E$4)*(ROW($B$3:$B$27)<=$F$4)*($C$3:$C$27<0),$C$3:$C$27)

    =SUMPRODUCT(($B$3:$B$27<=$H$4)*(ROW($B$3:$B$27)>=$E$4)*(ROW($B$3:$B$27)<=$F$4)*($C$3:$C$27>0),$C$3:$C$27)

    =SUMPRODUCT(($B$3:$B$27<=$H$4)*(ROW($B$3:$B$27)>=$E$4)*(ROW($B$3:$B$27)<=$F$4)*($C$3:$C$27<0),$C$3:$C$27)


    =SUMPRODUCT(($B$3:$B$27>=$H$4)*(ROW($B$3:$B$27)>=$E$4)*(ROW($B$3:$B$27)<=$F$4)*($C$3:$C$27>0))

    =SUMPRODUCT(($B$3:$B$27>=$H$4)*(ROW($B$3:$B$27)>=$E$4)*(ROW($B$3:$B$27)<=$F$4)*($C$3:$C$27<0))

    =SUMPRODUCT(($B$3:$B$27<=$H$4)*(ROW($B$3:$B$27)>=$E$4)*(ROW($B$3:$B$27)<=$F$4)*($C$3:$C$27>0))

    =SUMPRODUCT(($B$3:$B$27<=$H$4)*(ROW($B$3:$B$27)>=$E$4)*(ROW($B$3:$B$27)<=$F$4)*($C$3:$C$27<0))
    Attached Files Attached Files
    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 Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,193

    Re: Want formula to find sum of differences of values >= or <= than a reference value

    In J4

    =SUMIFS($C$3:C$23,C$3:C$23,">0",$B$3:$B$23,">=" &H4)

    in J10

    =COUNTIFS(C$3:C$23,">0",$B$3:$B$23,">=" &H4)

    You should be able to work out the other formulae.

    Check you results: B11 and B20 are both 50 with +ve differences

    And you cannot have both tests >= or <= : either >=50 and <50 OR >50 and <= 50
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  4. #4
    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. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: Want formula to find sum of differences of values >= or <= than a reference value

    @John

    I think we are meant to include the sequence row numbers, hence my confusion. The OP seems to be asking for one thing, but giving expected results for something else.

  5. #5
    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. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: Want formula to find sum of differences of values >= or <= than a reference value

    Anomalies highlighted to the right:

    AliGW on MS365 Beta Channel (Windows 11) 64 bit

    A
    B
    C
    D
    2
    Vlues
    Differences
    3
    25
    4
    28
    3
    5
    35
    7
    6
    30
    -5
    7
    25
    -5
    8
    30
    5
    9
    35
    5
    10
    40
    5
    11
    50
    10
    12
    52
    2
    13
    55
    3
    14
    60
    5
    15
    55
    -5
    16
    50
    -5
    17
    45
    -5
    18
    40
    -5
    19
    45
    5
    20
    50
    5
    21
    52
    2
    22
    55
    3
    23
    52
    -3
    24
    55
    3
    25
    56
    1
    26
    54
    -2
    27
    50
    -4
    Sheet: Sheet1

    AliGW on MS365 Beta Channel (Windows 11) 64 bit

    F
    G
    14
    Values >= 50
    15
    Values <= 50
    Sheet: Sheet1

  6. #6
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,193

    Re: Want formula to find sum of differences of values >= or <= than a reference value

    @Ali,
    I think we are meant to include the sequence row numbers
    You are right .. hence your use of SUMPRODUCT!

  7. #7
    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. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: Want formula to find sum of differences of values >= or <= than a reference value

    At this juncture, som input from the OP would be really helpful.

  8. #8
    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. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: Want formula to find sum of differences of values >= or <= than a reference value

    Nothing ...

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, if you have not already done so, you may not be aware that you can thank those who have helped you by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of all those who offered help.

  9. #9
    Registered User
    Join Date
    06-01-2022
    Location
    UK
    MS-Off Ver
    2021
    Posts
    16

    Re: Want formula to find sum of differences of values >= or <= than a reference value

    Hi, AliGW

    Please give me some time my issue is not resolved yet.

    Also i am writing a reply in more depth that would explain my expected results. Also this will eliminate the Anomalies coming at B11, B16 and B20.

    I would take 30 to 40 minutes more to write all my detailed reply explaining it all.


    Thanks

  10. #10
    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. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: Want formula to find sum of differences of values >= or <= than a reference value

    OK - thanks for checking in. It would have been a good idea to mention this sooner, though, otherwise helpers are left hanging. Please bear this in mind in future.

  11. #11
    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. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: Want formula to find sum of differences of values >= or <= than a reference value

    These match your expected results:

    AliGW on MS365 Beta Channel (Windows 11) 64 bit

    I
    J
    17
    >50
    =SUMPRODUCT(($B$3:$B$27>$H$4)*(ROW($B$3:$B$27)>=$E$4)*(ROW($B$3:$B$27)<=$F$4)*($C$3:$C$27>0),$C$3:$C$27)
    18
    >=50
    =SUMPRODUCT(($B$3:$B$27>=$H$4)*(ROW($B$3:$B$27)>=$E$4)*(ROW($B$3:$B$27)<=$F$4)*($C$3:$C$27<0),$C$3:$C$27)
    19
    <=50
    =SUMPRODUCT(($B$3:$B$27<=$H$4)*(ROW($B$3:$B$27)>=$E$4)*(ROW($B$3:$B$27)<=$F$4)*($C$3:$C$27>0),$C$3:$C$27)
    20
    <50
    =SUMPRODUCT(($B$3:$B$27<$H$4)*(ROW($B$3:$B$27)>=$E$4)*(ROW($B$3:$B$27)<=$F$4)*($C$3:$C$27<0),$C$3:$C$27)
    21
    22
    >50
    =SUMPRODUCT(($B$3:$B$27>$H$4)*(ROW($B$3:$B$27)>=$E$4)*(ROW($B$3:$B$27)<=$F$4)*($C$3:$C$27>0))
    23
    >=50
    =SUMPRODUCT(($B$3:$B$27>=$H$4)*(ROW($B$3:$B$27)>=$E$4)*(ROW($B$3:$B$27)<=$F$4)*($C$3:$C$27<0))
    24
    <=50
    =SUMPRODUCT(($B$3:$B$27<=$H$4)*(ROW($B$3:$B$27)>=$E$4)*(ROW($B$3:$B$27)<=$F$4)*($C$3:$C$27>0))
    25
    <50
    =SUMPRODUCT(($B$3:$B$27<$H$4)*(ROW($B$3:$B$27)>=$E$4)*(ROW($B$3:$B$27)<=$F$4)*($C$3:$C$27<0))
    Sheet: Sheet1

    However, to make them do so, I have had to change the formula so that some use >=50, some >50, some <=50 and some <50 - this is a weird inconsistency, if it is intended.
    Attached Files Attached Files
    Last edited by AliGW; 06-09-2022 at 05:14 AM. Reason: Workbook attached.

  12. #12
    Registered User
    Join Date
    06-01-2022
    Location
    UK
    MS-Off Ver
    2021
    Posts
    16

    Re: Want formula to find sum of differences of values >= or <= than a reference value

    Hi, AliGW


    My expected results are those mentioned in the file. I have calculated them manually but these results i want.

    Now i came to know that there is a error (Anomalies) that comes on at B11, B16 and B20. I know due to this my expected result would not come up.

    Please let me explain in an other way with which Anomalies would be resolved

    From here onward First Condition starts till C11.

    C4
    As my values are from cell B3 onward. Now difference in cell C4 comes out as
    =B4-B3
    As, B4=28 and B3=25 so,
    =28-25
    =3
    First Condition
    (If any of the two values of (B3 and B4) is equal to or less than reference value 50 and other one must less than 50. Then this difference value will go to L4 if it +ive and M4 if it -ive.)
    As in this C4 case both B4 and B3 are less than Reference value. so their output value +3 should go to the sum formula of L4.

    C5
    Difference in cell C5 comes out as
    =B5-B4
    As, B5=35 and B4=28 so,
    =35-28
    =7
    As in this C5 case both B5 and B4 are less than Reference value. so their output value +7 should go to the sum formula of L4.

    C6
    Difference in cell C6 comes out as
    =B6-B5
    As, B6=30 and B5=35 so,
    =30-35
    =-5
    As in this C6 case both B6 and B5 are less than Reference value. so their output value -5 should go to the sum formula of M4.

    C7
    Difference in cell C7 comes out as
    =B7-B6
    As, B7=25 and B6=30 so,
    =25-30
    =-5
    As in this C7 case both B7 and B6 are less than Reference value. so their output value -5 should go to the sum formula of M4.

    C8
    Difference in cell C8 comes out as
    =B8-B7
    As, B8=30 and B7=25 so,
    =30-25
    =+5
    As in this C8 case both B8 and B7 are less than Reference value. so their output value +5 should go to the sum formula of L4.

    C9
    Difference in cell C9 comes out as
    =B9-B8
    As, B9=35 and B8=30 so,
    =35-30
    =+5
    As in this C9 case both B9 and B8 are less than Reference value. so their output value +5 should go to the sum formula of L4.

    C10
    Difference in cell C10 comes out as
    =B10-B9
    As, B10=40 and B9=35 so,
    =40-35
    =+5
    As in this C10 case both B10 and B9 are less than Reference value. so their output value +5 should go to the sum formula of L4.

    C11
    Difference in cell C11 comes out as
    =B11-B10
    As, B11=50 and B10=40 so,
    =50-40
    =+10
    As in this C11 case, B11 is equal to reference value 50 and B10 is less than Reference value. So, Condition First is Satisfied so their output value +10 should go to the sum formula of L4.

    From here onward Second Condition starts till C16.

    C12
    Difference in cell C12 comes out as
    =B12-B11
    As, B12=52 and B11=50 so,
    =52-50
    =+2

    Second Condition
    (if any of the two values of (B12 and B11) is equal to or Greater than reference value 50 and other one must Greater than 50. Then this difference value will go to J4 if it +ive and K4 if it -ive.)
    As in this C12 case, B12 is greater than reference value 50 and B11 is equal to Reference value. So, Condition Second is Satisfied so their output value +2 should go to the sum formula of J4.


    C13
    Difference in cell C13 comes out as
    =B13-B12
    As, B13=55 and B12=52 so,
    =55-52
    =+3

    As in this C13 case, both B13 and B12 are greater than Reference value. So, Condition Second is Satisfied so their output value +3 should go to the sum formula of J4.


    C14
    Same above case for Cell C14.


    C15
    Difference in cell C15 comes out as
    =B15-B14
    As, B15=55 and B14=60 so,
    =55-60
    =-5
    As in this C15 case, both B15 and B14 are greater than Reference value. So, Condition Second is Satisfied so their output value -5 should go to the sum formula of K4.


    C16
    Difference in cell C16 comes out as
    =B16-B15
    As, B16=50 and B15=55 so,
    =50-55
    =-5

    As in this C16 case, both B16 and B15 are greater than Reference value. So, Condition Second is Satisfied so their output value -5 should go to the sum formula of K4.



    C17
    Difference in cell C17 comes out as
    =B17-B16
    As, B17=45 and B16=50 so,
    =45-50
    =-5

    As in this C17 case, B16 is equal to Reference value 50 and B17 is less than reference value 50, so condition First is satisfied. So, their output value -5 should go to the sum formula of M4.


    And So on for other cells.

  13. #13
    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. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: Want formula to find sum of differences of values >= or <= than a reference value

    So, given the mistakes you made with your data, do the formulae I gave you in post #2 now work? If not, do the ones in post #11 work?

    Let me know before I try to get my head around post #12.

    If you want more help, then please provide a corrected workbook with accurate expected results.
    Last edited by AliGW; 06-09-2022 at 05:21 AM. Reason: Typo fixed.

  14. #14
    Registered User
    Join Date
    06-01-2022
    Location
    UK
    MS-Off Ver
    2021
    Posts
    16

    Re: Want formula to find sum of differences of values >= or <= than a reference value

    Hi AliGW

    Thank you so much. Formula in Post 12 Works well.

    Thank you again for your help.

  15. #15
    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. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,780

    Re: Want formula to find sum of differences of values >= or <= than a reference value

    Glad to have helped.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

    Also, if you have not already done so, you may not be aware that you can thank those who have helped you by clicking the small star icon (* Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of all those who offered help.

+ 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. Replies: 3
    Last Post: 01-05-2019, 11:37 AM
  2. Formula to calculate, then sum, the differences between multiple values
    By Feby0900 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-22-2017, 01:03 PM
  3. Replies: 9
    Last Post: 03-31-2016, 06:24 PM
  4. Replies: 6
    Last Post: 02-05-2016, 12:35 PM
  5. Replies: 0
    Last Post: 04-13-2015, 01:01 PM
  6. [SOLVED] Need formula or Macro to help find differences between two tables of data
    By geckony in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 04-08-2014, 05:27 AM
  7. Replies: 14
    Last Post: 10-25-2012, 10:33 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