+ Reply to Thread
Results 1 to 12 of 12

IF function performing logical test on multiple cells

  1. #1
    Registered User
    Join Date
    11-11-2009
    Location
    Waterloo, Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    6

    IF function performing logical test on multiple cells

    Hi everyone,

    So my current problem is that I want to use the IF function to perform the logical test on a column of cells instead of just one cell.

    I realize that this can be done by copying the IF function to multiple cells but the way my spreadsheet is currently set up doesn't allow me to do that.

    To be more specific, I am trying to use the below function:
    Please Login or Register  to view this content.
    What I am trying to do is to go through a column of dates, extract the month and compare each month with a specific month. If the date matches up, I want to sum up data in an adjacent field based on another "equal to" criteria.

    I know the SUMIF portion is working fine but I am at a lost as to how to perform an IF logical test on a column of cells (compare a column of cells one by one to another specific cell) all in one cell (without having to use multiple cells and summing things up).

    Maybe this will be an interesting riddle for you guys =)

    Any help or advice is much appreciated!

    I forgot to mention that Excel doesn't let me use the IF function on a column of cells, haha. Well, it does but it isn't working as I expect it to as described above.
    Last edited by Omni; 11-12-2009 at 02:04 AM.

  2. #2
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: IF function performing logical test on multiple cells

    Maybe this will become clearer after you upload a workbook with some sample data, but I suspect SUMPRODUCT might be your ticket, as in

    =SUMPRODUCT(--MONTH(DateRange)=MONTH(CellValue)),SumRange)

    or something like that.

    Click "Go Advanced" below and then the paper clip icon to upload a (small!) data sample that illustrates what you want to achieve.

    cheers

  3. #3
    Registered User
    Join Date
    11-11-2009
    Location
    Waterloo, Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: IF function performing logical test on multiple cells

    Hi teylyn,

    Thank you for the quick reply!

    Before uploading a sample, I would just like to see if I can figure this out by myself. I am currently reading up on the SUMPRODUCT function.

    If I still can't figure it out, I will be more than happy to post my current file, hehe.

  4. #4
    Registered User
    Join Date
    11-11-2009
    Location
    Waterloo, Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: IF function performing logical test on multiple cells

    After learning about SUMPRODUCT (which does seem to be the answer to what I'm looking for), I am still encountering some error.

    I have tried to apply my new knowledge of SUMPRODUCT in cell D6 of the "Monthly Breakdown" worksheet. The adjacent cells are filled with my old formula of which I thought worked but has failed me.

    Note that there is a lot of text in my current formulas because I am using Excel basics to achieve the results I desire. However, all that text can be shrunk to a third of the size because they are just repetitions of the multi-conditional summing that I want to do on multiple sheets.

    The January column shows the goal of what I am trying to achieve. However, that column is currently tabulating all the values as a result of multi-conditional summing minus/regardless of the Months aspect.

    I hope this all makes sense and the sample helps you to understand more of what I am trying to do! =)
    Attached Files Attached Files

  5. #5
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: IF function performing logical test on multiple cells

    Commendations for wanting to do it on your own. Unless you've already found this one, it's one of the best discussions of SUMPRODUCT on the net

    http://www.xldynamic.com/source/xld.SUMPRODUCT.html

  6. #6
    Registered User
    Join Date
    11-11-2009
    Location
    Waterloo, Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: IF function performing logical test on multiple cells

    Hi Teylyn,

    That is indeed where I just learned about SUMPRODUCT! =D

  7. #7
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: IF function performing logical test on multiple cells

    The problem lies with the range P1:P9999 in Sheet TD Values containing not just dates but also text and blank values, so the construct

    =Date(Year....)) will return #Value! and the whole formula bombs.

    Delete the rows with the column headers that separate your monthly data, and give it another go.

    I'll get onto this later, but I'll have to feed the kids first. Din-Din time in NZ.

    cheers

  8. #8
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: IF function performing logical test on multiple cells

    Given you're using XL2007 you can / should really use SUMIFS function in preference to SUMPRODUCT given it is more efficient (significantly so in truth), eg:

    Please Login or Register  to view this content.
    In regard to the SUMPRODUCT... the #VALUE! error will as teylyn points out be generated wherever either date ranges or summation ranges contain non numerics - this is because of the explicit coercion being undertaken via the * of the arrays and the use of the MONTH function.

    On that basis it's better (IMO) to use double unary (to remove issues re: summation range - no explicit coercion - think SUM(A1:B1) rather than A1+B1) but also to use a TEXT check on the date range rather than a coercion technique - though this is slower (according to Bob - author of the link referenced), eg:

    Please Login or Register  to view this content.
    The advantage of SUMPRODUCT over SUMIFS is that it is backwards compatible with earlier versions ... if not needed use SUMIFS.
    If using SUMPRODUCT I would recommend you look into setting up Dynamic Named Ranges to restrict the size of the ranges being referenced, in the above you are processing nearly 30000 cells - repeated multiple times - will lead to slowdown in performance.

  9. #9
    Forum Expert teylyn's Avatar
    Join Date
    10-28-2008
    Location
    New Zealand
    MS-Off Ver
    Excel 365 Insider Fast
    Posts
    11,372

    Re: IF function performing logical test on multiple cells

    Suggestion:

    In your sheet "TD Debit", freeze the panes so that the first three rows stay in place.
    Delete the header rows separating the months
    If desired, apply conditional formatting to highlight the start of a new month.
    Now, this formula in the "Monthly Breakdown" sheet in D4 will work

    =SUMPRODUCT((YEAR('TD Debit'!$P$4:$P$9999)=YEAR('Monthly Breakdown'!D3))*(MONTH('TD Debit'!$P$4:$P$9999)=MONTH('Monthly Breakdown'!D3))*('TD Debit'!$C$4:$C$9999="P")*('TD Debit'!$R$4:$R$9999))

    Note the difference to your original formula. I got rid of the =Date(Year...,Month...,1) construct, and instead introduced two conditions, one looking at the year and the other one at the month. And the arrays start in row 4 instead of 1, so they don't include cells that will return errors on the date check.

    Some general thoughts about your spreadsheet design:

    The totalling you want to do, can also be achieved with Pivot tables, which will not eat as much computing power. Pivot tables should actually be the preferred solution, although the result can be achieved with SUMPRODUCT.

    SUMPRODUCT, though, especially when it references big ranges, can result in slow calculations.

    You are using fixed ranges like P1:P9999 in the Sumproduct arrays. The Sumproduct formula has four arrays to work with, totalling 40000 values to compute for each application of the formula. Don't be surprised if your workbook gets slow.

    If you decide against pivot tables, you may be better off if you define dynamic ranges names for your source data instead of hard-coding more cells than you need.

    A range name for the data column, for instance could be defined as DebitDates with the formula

    =OFFSET('TD Debit'!$P$4,0,0,COUNTA('TD Debit'!$P:$P)-2,1)

    Similarly, you can define dynamic ranges for the Dining and Debit columns

    DebitDining =OFFSET(DebitDates,0,-13)
    Debit =OFFSET(DebitDates,0,2)

    These ranges will grow and shrink with the data and will only contain the rows that are actually used ... and won't eat as much processing power when used in a SUMPRODUCT. The formula above could be changed to

    =SUMPRODUCT((YEAR(DebitDates)=YEAR('Monthly Breakdown'!D3))*(MONTH(DebitDates)=MONTH('Monthly Breakdown'!D3))*(DebitDining="P")*(Debit))

    Makes a little better reading, don't you agree?

    Let me know how you get on.

    hth

  10. #10
    Registered User
    Join Date
    11-11-2009
    Location
    Waterloo, Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: IF function performing logical test on multiple cells

    Wow, Looks like I have lots of reading and modifying to do.

    I'll be sure to get back to you guys once I've crunched all this info!
    Might be awhile though as projects and assignments are piling up again, haha.

    Thanks for the help thus far!

  11. #11
    Registered User
    Join Date
    11-11-2009
    Location
    Waterloo, Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    6

    Re: IF function performing logical test on multiple cells

    Hi guys,

    Just to let you know, my spreadsheet is now working and is much sexier than before, haha!

    Thanks for telling me about SUMPRODUCT and freezing panes and Dynamic Range Names!

    Excel has a lot more functionality than I originally thought. =)

    You guys are awesome, keep helping people out! =D
    Last edited by Omni; 11-12-2009 at 02:04 AM.

  12. #12
    Registered User
    Join Date
    12-01-2012
    Location
    matara,sri lanka
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: IF function performing logical test on multiple cells

    I need to compair two coloums and answer must be letter
    example:
    A2>=60 & b2>=5 answer=a

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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