+ Reply to Thread
Results 1 to 12 of 12

Sumproduct with Dynamic Column Headings

  1. #1
    Registered User
    Join Date
    03-03-2015
    Location
    New York
    MS-Off Ver
    2010
    Posts
    17

    Sumproduct with Dynamic Column Headings

    Hello,

    I've got a sumproduct formula based on multiple criteria, that is currently based on static columns (4Q16 data). I want the ability to have a toggle field (cell D31) that will allow me to switch the columns being used in the sumproduct based on the setting in the toggle field (eg. change to 3Q16 Data). I have attached my workbook to help find a solution. The highlighted portions of the formula (blue and green) are what I need to be tied to the column heading (cells E33 & E34) determined by the toggle cell (D31). I'm thinking INDEX MATCH, but I can't figure out how to incorporate that into my sumproduct formula.

    Please let me know if you need me to clarify anything and I thank you in advance for your assistance.
    Attached Files Attached Files

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

    Re: Sumproduct with Dynamic Column Headings

    Try this (the toggle cell is in fact D29):

    =SUMPRODUCT(--(C15:C2000="WML"),--(H15:H2000="Y"),CHOOSE(LOOKUP(D29,{"3Q16","4Q16"},{1,2}),D15:D2000,F15:F2000),CHOOSE(LOOKUP(D29,{"3Q16","4Q16"},{1,2}),E15:E2000,G15:G2000))/SUMPRODUCT(--(C15:C2000="WML"),--(H15:H2000="Y"),CHOOSE(LOOKUP(D29,{"3Q16","4Q16"},{1,2}),E15:E2000,G15:G2000))
    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.

  3. #3
    Registered User
    Join Date
    03-03-2015
    Location
    New York
    MS-Off Ver
    2010
    Posts
    17

    Re: Sumproduct with Dynamic Column Headings

    Hi Ali,

    Thank you for your proposed solution, however, this is just a small piece of the data I am working with (I reduced the file size to satisfy the excelforums file upload parameters). I actually have a lot of historical data (goes back several years) and I would rather not have to build all those choices (eg. 1Q14, 3Q12, 2Q10) into the formula. I've been able to build a sumifs formula that uses the index match logic that I'm thinking of (see below), however, I can't seem to replicate for my sumproduct formula.

    =SUMIFS(INDEX($C$16:$H$2000,0,MATCH((TEXT($D$29&" Curr P18-49 Imp",0)),$C$15:$H$15,0)),$C$16:$C$2000,"WML",$H$16:$H$2000,"Y")

  4. #4
    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
    80,916

    Re: Sumproduct with Dynamic Column Headings

    Maybe somebody else can take this on, as I have to go offline shortly. It's always best to state the real parameters at the outset, even if you can't actually share them in your sample file.

  5. #5
    Forum Expert
    Join Date
    10-10-2016
    Location
    Sheffield
    MS-Off Ver
    365 and rarely 2016
    Posts
    3,212

    Re: Sumproduct with Dynamic Column Headings

    Very quick reply from your sample file but something along the lines of
    =SUMPRODUCT((C16:C23="WML")*(H16:H23="Y")*(OFFSET(C16,0,D31,8,1))*(OFFSET(D16,0,D31,8,1)))/SUMPRODUCT((C16:C23="WML")*(H16:H23="Y")*(OFFSET(D16,0,D31,8,1)))

    where d31 is =MATCH(E31,D15:G15,0)

    might work, as the ranges will dynamically change as a result of the match function, hopefully a start

  6. #6
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: Sumproduct with Dynamic Column Headings

    Based on davsth's solution:

    Try

    =SUMPRODUCT(($C$16:$C$23="WML")*($H$16:$H$23="Y")*(OFFSET($C$16,0,$D$31,8,1))*(OFFSET($C$16,0,$D$31+1,8,1)))/SUMPRODUCT(($C$16:$C$23="WML")*($H$16:$H$23="Y")*(OFFSET($C$16,0,$D$31+1,8,1)))

    in D31

    =MATCH($D$29& "*",$D$15:$G$15,0)

    OR

    =IFERROR(SUMPRODUCT(($C$16:$C$23="WML")*($H$16:$H$23="Y")*(OFFSET($C$16,0,MATCH($D$29& "*",$D$15:$G$15,0),8,1))*(OFFSET($C$16,0,MATCH($D$29& "*",$D$15:$G$15,0)+1,8,1)))/SUMPRODUCT(($C$16:$C$23="WML")*($H$16:$H$23="Y")*(OFFSET($C$16,0,MATCH($D$29& "*",$D$15:$G$15,0)+1,8,1))),"")


    MATCH included in formula
    Attached Files Attached Files
    Last edited by JohnTopley; 10-24-2016 at 02:37 PM.

  7. #7
    Registered User
    Join Date
    03-03-2015
    Location
    New York
    MS-Off Ver
    2010
    Posts
    17

    Re: Sumproduct with Dynamic Column Headings

    Hi John,

    Unfortunately, the report I will be dumping in will have a dynamic number of rows, so based on the formula you offered me, i would have to count the number of rows in the report each time and change the row count in the offset formula. I was envisioning, the only cell that I change (after dumping in the new data) would be the toggle switch (no changes to the formula). That's why I keep coming back to Index Match, because that should search for you no matter how many rows of data there are in the report each time. (that's also, why the formula was set to 2000 rows in the first place, because i know it will never be MORE than 2000 rows of data). I apologize if I should have stated this in my initial post (I'm quickly learning forum etiquette)

  8. #8
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: Sumproduct with Dynamic Column Headings

    Try

    ... no OFFSET ...


    =IFERROR(SUMPRODUCT(($C$16:$C$2000="WML")*($H$16:$H$2000="Y")*(INDEX($D$16:$G$2000,,MATCH($K$30& "*",$D$15:$G$15,0)))*(INDEX($D$16:$G$2000,,MATCH($K$30& "*",$D$15:$G$15,0)+1)))/SUMPRODUCT(($C$16:$C$2000="WML")*($H$16:$H$2000="Y")*(INDEX($D$16:$G$2000,,MATCH($K$30& "*",$D$15:$G$15,0)+1))),"")

    K30 is your drop down (Period) selection
    Attached Files Attached Files
    Last edited by JohnTopley; 10-24-2016 at 05:34 PM.

  9. #9
    Registered User
    Join Date
    03-03-2015
    Location
    New York
    MS-Off Ver
    2010
    Posts
    17

    Re: Sumproduct with Dynamic Column Headings

    I update the K30 to D29 to match the spreadsheet, but unfortunately, that did not work. I am getting #VALUE. I feel like we're so close now that we have the Index Match embedded.

    =IFERROR(SUMPRODUCT(($C$16:$C$2000="WML")*($H$16:$H$2000="Y")*(INDEX($D$16:$G$2000,,MATCH($D$29& "*",$D$15:$G$15,0)))*(INDEX($D$16:$G$2000,,MATCH($D$29& "*",$D$15:$G$15,0)+1)))/SUMPRODUCT(($C$16:$C$2000="WML")*($H$16:$H$2000="Y")*(INDEX($D$16:$G$2000,,MATCH($D$29& "*",$D$15:$G$15,0)+1))),"")

    K30 is your drop down (Period) selection

  10. #10
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: Sumproduct with Dynamic Column Headings

    You can't use D29 as it is in a column (D16:D2000) that is in the formula: that is why I moved it.

    See attached:


    =IFERROR(SUMPRODUCT(($C$16:$C$2000="WML")*($D$16:$D$2000="Y")*(INDEX($E$16:$ZZ$2000,,MATCH($E$3& "*",$E$15:$ZZ$15,0)))*(INDEX($E$16:$ZZ$2000,,MATCH($E$3& "*",$E$15:$ZZ$15,0)+1)))/SUMPRODUCT(($C$16:$C$2000="WML")*($D$16:$D$2000="Y")*(INDEX($E$16:$ZZ$2000,,MATCH($E$3& "*",$E$15:$ZZ$15,0)+1))),"")

    I moved drop down to E3 and column I to D to the period columns are now contiguous.
    Attached Files Attached Files
    Last edited by JohnTopley; 10-24-2016 at 11:53 PM.

  11. #11
    Registered User
    Join Date
    03-03-2015
    Location
    New York
    MS-Off Ver
    2010
    Posts
    17

    Re: Sumproduct with Dynamic Column Headings

    Thank you John. This worked perfectly. Reputation stars are on on the way!!

  12. #12
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    28,209

    Re: Sumproduct with Dynamic Column Headings

    Thank you the feedback and rep.

    Glad it's sorted!

+ 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] Sumproduct not updating with dynamic column addition
    By AndyE in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-25-2015, 03:56 PM
  2. SUMPRODUCT using 2 column headings as criteria
    By ac01 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-09-2014, 01:07 PM
  3. VBa Dynamic Monthly Column Headings
    By hobbiton73 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-03-2014, 05:03 AM
  4. [SOLVED] SumProduct of Unique values in a dynamic length column
    By ddander54 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-20-2013, 05:24 PM
  5. Dynamic column headings
    By ianh in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-10-2013, 10:53 AM
  6. Replies: 1
    Last Post: 01-21-2011, 07:24 AM
  7. [SOLVED] Can I invert a table so row headings are now column headings etc
    By Sharon in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-10-2005, 04:06 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