+ Reply to Thread
Results 1 to 6 of 6

Formula Combining the SUMIF and LEFT functions to calculate totals

  1. #1
    Valued Forum Contributor
    Join Date
    09-09-2009
    Location
    Liverpool, England
    MS-Off Ver
    W: 2021 H: 365
    Posts
    940

    Formula Combining the SUMIF and LEFT functions to calculate totals

    Hi,

    I'm sure there's a simple resolution to this but i'm sick of wasting my time on it. Basically i'm looking to calculate the total of two columns based on whether the data in the first column starts with 40 or 50.

    Thanks in advance,

    Snook
    Attached Files Attached Files

  2. #2
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,147

    Re: Formula Combining the SUMIF and LEFT functions to calculate totals

    hi Snook, try:
    =SUMPRODUCT((LEFT($B$3:$B$24,2)="40")*($C$3:$C$24))

    or change B27 to just 40. then use:
    =SUMPRODUCT((LEFT($B$3:$B$24,2)=B27&"")*($C$3:$C$24))

    1st formula must change the red text to "50" for B28. 2nd formula works for both

    Thanks, if you have clicked on the * and added our rep.

    If you're satisfied with the answer, click Thread Tools above your first post, select "Mark your thread as Solved".

    "Contentment is not the fulfillment of what you want, but the realization of what you already have."


    Tips & Tutorials I Compiled | How to Get Quick & Good Answers

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Formula Combining the SUMIF and LEFT functions to calculate totals

    The values in column B are numbers, so you I don't think you can use wildcards - I could be wrong though.

    Anyway, this formula worked for 40,
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    and this for 50.
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  4. #4
    Valued Forum Contributor
    Join Date
    09-09-2009
    Location
    Liverpool, England
    MS-Off Ver
    W: 2021 H: 365
    Posts
    940

    Re: Formula Combining the SUMIF and LEFT functions to calculate totals

    Thanks, for my own sanity and development where was I going wrong in relation to the formulas I had a bash at in the attached example?

    Thanks,

    Snook

  5. #5
    Forum Guru benishiryo's Avatar
    Join Date
    03-25-2011
    Location
    Singapore
    MS-Off Ver
    Excel 2013
    Posts
    5,147

    Re: Formula Combining the SUMIF and LEFT functions to calculate totals

    in your formula for C27, you are basically saying in B3:B24, find the statement "TRUE" & sum up C3:C24. that's because you used your criteria as LEFT(B3,2)="40". that is a logical test. you are saying is 2 characters from the left of B3 equals to "40"? so the answer is TRUE.

    if B3:B24 were to be texts, then you could use something like:
    =SUMIF($B$3:$B$24,"40*",$C$3:$C$24)
    but unfortunately, as nonie mentioned, SUMIF doesnt allow wildcards for numbers

  6. #6
    Valued Forum Contributor
    Join Date
    09-09-2009
    Location
    Liverpool, England
    MS-Off Ver
    W: 2021 H: 365
    Posts
    940

    Re: Formula Combining the SUMIF and LEFT functions to calculate totals

    Thanks both, that makes a lot more sense now!

    Another problem has now arisen, is it possible to amend the formula to pick up two criteria? I'm working with a much larger data set and need to add the codes "509" and "6".

    I've managed to achieve what i'm after by adding a SUM formula at the start and copying the SUMPRODUCT formula and amending it to incorporate the second criteria I require. This strikes me as long winded and i'm there must be a shorter alternative?

    Thanks

    Snook

+ 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