+ Reply to Thread
Results 1 to 4 of 4

Conditional Aggregation with Partial Match

Hybrid View

  1. #1
    Registered User
    Join Date
    12-07-2010
    Location
    Exeter, England
    MS-Off Ver
    Excel 2003
    Posts
    12

    Conditional Aggregation with Partial Match

    Hi Everyone,

    I have attached my spreadsheet and am hoping someone can find a way of doing the following:

    Under tab "PostCodes" you see the below, I want total Bookings to basically go through all of tab "Bookings" and count up all bookings that are made in the Year entered in Cell B1 of "PostCodes" that have the post code begin with the text in "PostCode" column. And then I also with to SUM the Total order value of those in the "Total Order Value" cell.

    Year: 2007

    PostCode Region Total Bookings Total Order Value
    AB Aberdeen
    AL St Albans
    B Birmingham
    BA Bath
    BB Blackburn
    BD Bradford
    BH Bournemouth
    BL Bolton
    BN Brighton

    Anyone know how to do this as I am going in absolute circles on this.

    Thanks,

    Chris
    Attached Files Attached Files
    Last edited by DonkeyOte; 12-30-2010 at 09:30 AM. Reason: modified title

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

    Re: COUNTIF Function and VLookup Help

    Chris, for info., both SUMIF & COUNTIF accept wildcards, however, in this instance you have an issue in so far as the post codes themselves are not mutually exclusive
    B* would for ex. include B, BA, BB, BD etc... which is not what you want

    Given the above, what I would suggest you do is add a further column to your source sheet which extracts the initial element of the post code:

    Bookings!R2
    =LEFT(G2,MIN(FIND({1,2,3,4,5,6,7,8,9,0},G2&1234567890)-1))
    copied down
    or if we assume 1 or 2 alphas only

    =LEFT(G2,2-ISNUMBER(0+MID(G2,2,1)))
    copied down
    Then use exact matches on this column

    PostCodes!C4:
    =COUNTIF(Bookings!$R:$R,$A4)
    copied down
    
    PostCodes!D4:
    =SUMIF(Bookings!$R:$R,$A4,Bookings!$M:$M)
    copied down

  3. #3
    Registered User
    Join Date
    12-07-2010
    Location
    Exeter, England
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: COUNTIF Function and VLookup Help

    That is great! Thank you.

    There is one issue though and that is that you are not taking into account the year field"PostCodes" tab Cell "B2" and this then correlates to the "Bookings" tab and Cell "Q2", so if I changed the Year to 2008 I would like it to then amend to bookings with year of Departure as 2008.

    Are you able to assist with that final piece? Thanks so much again!

    Chris

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

    Re: COUNTIF Function and VLookup Help

    For the sake of efficiency (calculations) modify as follows:

    Bookings!R2:
    =LEFT(G2,2-ISNUMBER(0+MID(G2,2,1)))&"@"&$Q2
    copied down
    Then

    PostCodes!C4:
    =COUNTIF(Bookings!$R:$R,$A4&"@"&$B$1)
    copied down
    
    PostCodes!D4:
    =SUMIF(Bookings!$R:$R,$A4&"@"&$B$1,Bookings!$M:$M)
    copied down
    the more common approach (pre XL2007) is to use SUMPRODUCTs, however, these functions are inefficient esp. when used in large volume or with large precedent ranges.

    Using a concatenated key as we have done in Col R is a good way of maintaining performance whilst still allowing for multi criteria tests.

    If you are using XL2007 or above you can use COUNTIFS and SUMIFS respectively but note that they are not backwards compatible.

+ 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