+ Reply to Thread
Results 1 to 8 of 8

COUNTIF in a 2D Array and multiply by value in the same row

  1. #1
    Registered User
    Join Date
    11-30-2020
    Location
    Melbourne, Australia
    MS-Off Ver
    Office 365
    Posts
    8

    COUNTIF in a 2D Array and multiply by value in the same row

    Hello all, long time reader, first time questioner.

    I have a spreadsheet with a set of movements through various sections (B:O) in the Routing tab, and the number of times they move in a given year (P:T). I need to return the amount of times they move through each section in each year in the Total by Section tab - a COUNTIF returns the number of times each section comes up, but for each I need to multiply it by the number of movements on the row in the Routing tab and I have been unable to figure out how to do this.

    For example, take ID3 in the Routing tab - it comes up 7 times in each year, so needs to increment the count against each of the relevant sections 7 times in the Total by Section tab.

    Thanks very much for your help.
    Attached Files Attached Files
    Last edited by Penguinton; 12-01-2020 at 06:41 PM. Reason: Solved

  2. #2
    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,946

    Re: COUNTIF in a 2D Array and multiply by value in the same row

    Would this work for you?

    =$F6*INDEX(Routing!P:P,MATCH('Total by section '!$A6,Routing!$A:$A,0))
    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

  3. #3
    Registered User
    Join Date
    11-30-2020
    Location
    Melbourne, Australia
    MS-Off Ver
    Office 365
    Posts
    8

    Re: COUNTIF in a 2D Array and multiply by value in the same row

    Thanks for the answer! I gave it a try - I'm afraid not as the ID figures in the Routing tab do not correspond to the IDs in Total by Section - the former is the ID of the service, the latter is the ID of the section name.

  4. #4
    Registered User
    Join Date
    11-30-2020
    Location
    Melbourne, Australia
    MS-Off Ver
    Office 365
    Posts
    8

    Re: COUNTIF in a 2D Array and multiply by value in the same row

    A colleague provided this, which certainly works but is quite unwieldy:

    =SUMIF(Routing!$B$3:$B$134,'Total by section '!$E5,Routing!P$3:P$134)+SUMIF(Routing!$C$3:$C$134,'Total by section '!$E5,Routing!P$3:P$134)+SUMIF(Routing!$D$3:$D$134,'Total by section '!$E5,Routing!P$3:P$134)+SUMIF(Routing!$E$3:$E$134,'Total by section '!$E5,Routing!$P4:$P135)+SUMIF(Routing!$F$3:$F$134,'Total by section '!$E5,Routing!$P4:$P135)+SUMIF(Routing!$G$3:$G$134,'Total by section '!$E5,Routing!$P4:$P135)+SUMIF(Routing!$H$3:$H$134,'Total by section '!$E5,Routing!$P4:$P135)+SUMIF(Routing!$I$3:$I$134,'Total by section '!$E5,Routing!$P4:$P135)+SUMIF(Routing!$J$3:$J$134,'Total by section '!$E5,Routing!$P4:$P135)+SUMIF(Routing!$K$3:$K$134,'Total by section '!$E5,Routing!$P4:$P135)+SUMIF(Routing!$L$3:$L$134,'Total by section '!$E5,Routing!$P4:$P135)+SUMIF(Routing!$M$3:$M$134,'Total by section '!$E5,Routing!$P4:$P135)+SUMIF(Routing!$N$3:$N$134,'Total by section '!$E5,Routing!$P4:$P135)+SUMIF(Routing!$O$3:$O$134,'Total by section '!$E5,Routing!$P4:$P135)

    As there are up to 24 sections to consider in the actual spreadsheet, I'd be very grateful if someone could provide a more elegant solution.

  5. #5
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: COUNTIF in a 2D Array and multiply by value in the same row

    Hi, you can use below:

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    note: your SUMIF approach above will produce different results as the absolute referencing for sections E:O are incorrect, should be P$3:P$134 as opposed to $P3:$P134
    once corrected the SUMIF approach will generate the same results as the above

  6. #6
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,612

    Re: COUNTIF in a 2D Array and multiply by value in the same row

    IN G4 and copied across

    =SUMPRODUCT(COUNTIF(OFFSET(Routing!$B$3:$O$3,ROW(Routing!$A$3:$A$105)-ROW(Routing!$A$3),0),$E4)*(Routing!P$3:P$105))
    Attached Files Attached Files
    Pl note
    Array formula should be confirmed with Ctrl+Shift+Enter keys together.
    If answere is satisfactory press * to add reputation.

  7. #7
    Forum Expert XLent's Avatar
    Join Date
    10-13-2010
    Location
    Northumberland, UK
    MS-Off Ver
    various
    Posts
    2,704

    Re: COUNTIF in a 2D Array and multiply by value in the same row

    can you explain why you would choose to offer an inefficient and volatile SUMPRODUCT construct when it has already been shown to be unnecessary

    what am I missing ? are you taking the thread title as a literal requirement ?

  8. #8
    Registered User
    Join Date
    11-30-2020
    Location
    Melbourne, Australia
    MS-Off Ver
    Office 365
    Posts
    8

    Re: COUNTIF in a 2D Array and multiply by value in the same row

    Quote Originally Posted by XLent View Post
    Hi, you can use below:

    Formula: copy to clipboard
    Please Login or Register  to view this content.
    note: your SUMIF approach above will produce different results as the absolute referencing for sections E:O are incorrect, should be P$3:P$134 as opposed to $P3:$P134
    once corrected the SUMIF approach will generate the same results as the above
    This solution works perfectly, thank you very much for your 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. [SOLVED] multiply countif outcome
    By janbaetens in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-09-2018, 07:59 AM
  2. [SOLVED] Countif with a multiply critera to collumns value
    By Challebjoern in forum Excel General
    Replies: 14
    Last Post: 07-12-2018, 06:01 AM
  3. [SOLVED] [SOLVED} array of discount multiply to array of amount
    By kirby21 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-03-2014, 11:31 PM
  4. Multiply COUNTIF by criteria in same row.
    By Belfast_stu in forum Excel General
    Replies: 11
    Last Post: 02-10-2011, 05:30 PM
  5. Trick to multiply an array without an array formula
    By kayard in forum Excel General
    Replies: 2
    Last Post: 12-16-2010, 05:07 AM
  6. Countif then multiply
    By Gee-off in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-07-2005, 05:25 PM
  7. [SOLVED] Countif, then multiply??
    By Gee-off in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 12-07-2005, 05:00 PM

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