+ Reply to Thread
Results 1 to 21 of 21

IF() formula by summing two ranges (instead of two cells)

  1. #1
    Registered User
    Join Date
    10-10-2016
    Location
    Coimbra, Portugal
    MS-Off Ver
    2016
    Posts
    86

    IF() formula by summing two ranges (instead of two cells)

    Hi.
    I have this IF() formula:
    =IF($AJ6+$AI6 <= AG5, 1, 0)

    How do I SUM all within $AI6:$AI178+$AJ6:$AJ178, relatively speaking, like so:

    IF $AJ6 + $AI6 <= AG5 THEN count 1
    IF $AJ7 + $AI7 <= AG5 THEN count 1
    all the way to...
    IF $AJ177 + $AI178 <= AG5 THEN count 1
    IF $AJ178 + $AI178 <= AG5 THEN count 1
    and then getting the total SUM?

    PR

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,832

    Re: IF() formula by summing two ranges (instead of two cells)

    Assuming I understand what you are doing, I would:

    1) Add a helper column that adds column AJ and AI: =$AJ6+$AI6 or =SUM($AI6:$AJ6)
    2) Then use a COUNTIFS() function based on that helper column =COUNTIFS(helpercolumn,"<="&AG5) https://support.office.com/en-us/art...c-aa8c2a866842

    Did I understand correctly? Will something like that work for you?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: IF() formula by summing two ranges (instead of two cells)

    Try this...
    AG
    AH
    AI
    AJ
    AK
    1
    5
    2
    1
    2
    1
    3
    2
    3
    1
    4
    3
    4
    1
    5
    12
    4
    5
    1
    6
    5
    6
    1
    7
    6
    7
    0
    8
    7
    8
    0
    9
    8
    9
    0
    10
    9
    10
    0
    11
    10
    11
    0



    AI1=SUMPRODUCT(--(AI2:AI11+AJ2:AJ11<=AG5))
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  4. #4
    Registered User
    Join Date
    10-10-2016
    Location
    Coimbra, Portugal
    MS-Off Ver
    2016
    Posts
    86

    Re: IF() formula by summing two ranges (instead of two cells)

    That's it.
    Just one thing: is it possible to ignore cells with 0 in the two ranges - in your case, AI2:AI11 and AJ2:AJ11?
    Thank you.

    PR

  5. #5
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: IF() formula by summing two ranges (instead of two cells)

    Maybe this (untested)...
    AI1=SUMPRODUCT(--(AI2:AI11+AJ2:AJ11<=AG5),--AI2:AI11+AJ2:AJ11>0))

  6. #6
    Registered User
    Join Date
    10-10-2016
    Location
    Coimbra, Portugal
    MS-Off Ver
    2016
    Posts
    86

    Re: IF() formula by summing two ranges (instead of two cells)

    It returns 0.

    PR

  7. #7
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: IF() formula by summing two ranges (instead of two cells)

    I have just tested that, and it worked fine...
    AG
    AH
    AI
    AJ
    AK
    1
    3
    4
    2
    0
    0
    1
    3
    0
    1
    1
    4
    1
    2
    1
    5
    5
    2
    3
    1
    6
    3
    4
    0
    7
    4
    5
    0
    8
    5
    6
    0
    9
    6
    7
    0
    10
    7
    8
    0
    11
    8
    9
    0


    AI1=SUMPRODUCT(--(AI2:AI11+AJ2:AJ11<=AG5),--(AI2:AI11+AJ2:AJ11>0))
    AK1=SUM(AK2:AK11)
    you will see that the sum of AK - which shows =--(AI2+AJ2<=$AG$5) - is 4, but my formula shows only 3...because the 1st set of data are both 0

  8. #8
    Registered User
    Join Date
    10-10-2016
    Location
    Coimbra, Portugal
    MS-Off Ver
    2016
    Posts
    86

    Re: IF() formula by summing two ranges (instead of two cells)

    There's a typo error in post #5 - you missed a parenthesis:
    AI1=SUMPRODUCT(--(AI2:AI11+AJ2:AJ11<=AG5),--AI2:AI11+AJ2:AJ11>0))

    Post #7:
    AI1=SUMPRODUCT(--(AI2:AI11+AJ2:AJ11<=AG5),--(AI2:AI11+AJ2:AJ11>0))

    I had corrected it to
    AI1=SUMPRODUCT(--(AI2:AI11+AJ2:AJ11<=AG5),--AI2:AI11+AJ2:AJ11>0)
    ... (without the parentheses) that's why it wasn't' working for me - now it's good.

    Unfortunately, things aren't functioning as expected in the worksheet I'm working on, because I see now that I've completely missed an additional column that I should've considered from the start.
    I apologize.
    I should probably mark this thread as solved and start a new one.
    Thank you again, FDibbins.

    PR

  9. #9
    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
    81,065

    Re: IF() formula by summing two ranges (instead of two cells)

    No, don't start a new thread. Just add the new details here. The solution will not be very far from what you have already, in all probability.
    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.

  10. #10
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: IF() formula by summing two ranges (instead of two cells)

    Yes, please continue here.

  11. #11
    Registered User
    Join Date
    10-10-2016
    Location
    Coimbra, Portugal
    MS-Off Ver
    2016
    Posts
    86

    Re: IF() formula by summing two ranges (instead of two cells)

    All right then.
    The main scenario is this:

    Example Sheet.jpg

    I'm trying to figure out how many people were born on the island, based on their Age, Year of Arrival and Year of Death (wasn't considering the Year of Death before).
    Also, the solution formula has to ignore "—" in some Year of Death cells.
    What's the best approach?
    I've been at this all day (really) and I still haven't figured out the logic/math of it.
    Any ideas?

    PR
    Attached Files Attached Files

  12. #12
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: IF() formula by summing two ranges (instead of two cells)

    This is what I have come up with so far...
    =SUMPRODUCT(--($W$4:$W$9+$U$4:$U$9<=$V$4:$V$9),--($V$4:$V$9>0))

    However, do you want to exclude qualifying entries with no death?

  13. #13
    Registered User
    Join Date
    10-10-2016
    Location
    Coimbra, Portugal
    MS-Off Ver
    2016
    Posts
    86

    Re: IF() formula by summing two ranges (instead of two cells)

    On the contrary, I need to include everyone - alive or dead. I need to know effectively how many people were born on the island (on the Year of Arrival or after it).
    As to your formula, if I change John's age to 10 - making him another island born - it doesn't add to the total.
    By the way, >0 should also be for $W$4:$W$9 and $U$4:$U$9 (it's for empty entries).


    PR
    Last edited by Pr0; 07-10-2018 at 01:47 PM.

  14. #14
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: IF() formula by summing two ranges (instead of two cells)

    You are only taking this up to 98, correct?
    How would you calc John's change manually?

  15. #15
    Registered User
    Join Date
    10-10-2016
    Location
    Coimbra, Portugal
    MS-Off Ver
    2016
    Posts
    86

    Re: IF() formula by summing two ranges (instead of two cells)

    Yes, 98 is the limit, the "today". The Age, Death and Arrival columns are all manual input. The columns 80 through 98 are where all the magic occurs.
    (The magic spells are all your doing, by the way )

    PR

  16. #16
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,832

    Re: IF() formula by summing two ranges (instead of two cells)

    I still haven't figured out the logic/math of it.
    and I am having a difficult time understanding it, too -- perhaps because you are having a difficult time.

    I find that I must first understand the logic/math of a problem before I can program it. Your example looks like it is trying to answer the question -- how many have been born (whether living or dead) on the island. I translated that into how many have an birth date on or after their arrival date. Note that year of death does not figure into this question. To program that I used a lookup function [INDEX(...,MATCH(...))] to get the year of birth. Then a simple boolean check to see if the year of birth is greater than or equal to arrival date. In your example, I count 4 who were born on the island.

    Year of death might figure into the question how many people were born on the island and are still living. Death is indicated by the m dash characters. This count would be the same as above, then subtract the number of those born on the island that have at least one em dash in their row. In your example, I count 3 who were born on the island and still living.

    I have not bothered sharing formulas, because I am still not sure of the logic behind the problem. I am hoping that this will give you a chance to clarify.

  17. #17
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: IF() formula by summing two ranges (instead of two cells)

    Quote Originally Posted by Pr0 View Post
    ...(The magic spells are all your doing, by the way )...
    Yes, I thought that looked familiar

  18. #18
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: IF() formula by summing two ranges (instead of two cells)

    This ARRAY formula is getting closer....
    =SUMPRODUCT(--($W$4:$W$9+$U$4:$U$9<=IF($V$4:$V$9="—",98,$V$4:$V$9)))
    entered with CSE
    it returns 2, and it changes to 3 is John is 10. BUT it excludes Alice because 86+13=99, which is outside the year range.

  19. #19
    Forum Expert
    Join Date
    06-08-2012
    Location
    Left the forum!
    MS-Off Ver
    Left the forum!
    Posts
    5,189

    Re: IF() formula by summing two ranges (instead of two cells)

    How about

    =SUMPRODUCT(($B$3:$T$3=$W$4:$W$9)*($B$4:$T$9<=1))

    edit:-

    And a slighlty simpler formula for B4:T9

    =IF(B$3>$V4,"—",MAX(0,IF($V4="—",$U4-COLUMNS(B4:$T4)+1,B$3-$V4+$U4)))
    Last edited by jason.b75; 07-10-2018 at 02:36 PM.

  20. #20
    Registered User
    Join Date
    10-10-2016
    Location
    Coimbra, Portugal
    MS-Off Ver
    2016
    Posts
    86

    Re: IF() formula by summing two ranges (instead of two cells)

    This formula seems to be working flawlessly in my worksheet.
    Quote Originally Posted by jason.b75 View Post
    =SUMPRODUCT(($B$3:$T$3=$W$4:$W$9)*($B$4:$T$9<=1))
    Also, it conveniently ignores "0" and "—" in some entries, which is exactly what I want.
    Thank you.

    As to MrShorty: in fact the only thing that matters is the total of people born on the island, regardless of still being alive or not.
    At first I started with just the Age and Arrival years, but, not being able to figure it out, I began to think that I also needed the Death year as well.

    FDibbins, MrShorty and jason.b75, thank you all so much.

    PR

  21. #21
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,939

    Re: IF() formula by summing two ranges (instead of two cells)

    happy to help, Im glad you got what you wanted

+ 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. Formula for summing cells
    By darijokesar in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-12-2017, 06:10 PM
  2. Summing set ranges separated by blank cells
    By jrx in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-11-2016, 05:37 AM
  3. Summing cells to left of formula
    By Mavbohs in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-13-2015, 11:58 AM
  4. Help with formula for conditional summing of cells
    By gailh in forum Excel General
    Replies: 2
    Last Post: 06-21-2012, 10:59 AM
  5. Summing cells where one has a formula
    By jacko311 in forum Excel General
    Replies: 4
    Last Post: 12-27-2009, 09:12 PM
  6. Formula about summing cells
    By LEIGHHAYES in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-11-2008, 12:10 AM
  7. Replies: 0
    Last Post: 08-28-2005, 10:50 AM

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