+ Reply to Thread
Results 1 to 14 of 14

DSUM with dynamic criteria?

  1. #1
    Registered User
    Join Date
    05-21-2007
    Posts
    79

    Smile DSUM with dynamic criteria?

    The Googles have done nothing for me as far as this question goes, so I come to you all on my knees, begging for some clarity.

    I have a large spreadsheet of data, with two columns containing the criteria I'd like to use to sum the rest of the data columns. Call these columns "Parlour" and "Toppings". The data columns show the number of parlours of a certain type that offer the corresponding topping for that row. Hence, there might be 5 Pizza Huts that offer Pineapple in one city (column), but only 2 Pizza Huts that offer Goat Cheese.

    On another sheet in the workbook, I have a list of parlours, and I want to know, for each parlour, how many locations in a given city offer a certain combination of toppings. My thought was to create a criteria range for the toppings, and a separate list of the parlours, so that the DSUM criteria would merge the ranges somehow. The idea would be to build in the ability to pull the formula down for any parlours that are added to the list, so that the toppings criteria stays the same, but the parlour criteria range is referenced at an offset position, corresponding to the new listing.

    Does this make sense? I can't seem to figure out how to modify the criteria field in the DSUM formula to take an array created with statements in it.

    Any ideas? All suggestions welcome, and thanks!
    Last edited by yellephant; 06-22-2011 at 04:47 PM. Reason: Solution achieved!

  2. #2
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: DSUM with dynamic criteria?

    To best describe or illustrate your problem you would be better off attaching a dummy workbook, the workbook should contain the same structure and some dummy data of the same type as the type you have in your real workbook - so, if a cell contains numbers & letters in this format abc-123 then that should be reflected in the dummy workbook.

    If needed supply a before and after sheet in the workbook so the person helping you can see what you are trying to achieve.

    Doing this will ensure you get the result you need!
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  3. #3
    Registered User
    Join Date
    05-21-2007
    Posts
    79

    Re: DSUM with dynamic criteria?

    Thanks for the quick response, NBVC!

    I think the attached dummy workbook ought to explain my problem. The "Old Method" tab shows the current setup of my workbook, and how the summary information is gathered. Changing the blue input causes the DSUM formulas to reference a different column in the data base, and sum the data according to the various criteria.

    What I'm looking for is a way to simplify the criteria to cut down on redundancy, and make it easier to update. The "New Method" tab shows what I'd like the criteria section to look like, but I don't know how to actually build this into an easy-to-use DSUM formula. I'd like to have criteria in place for the Pizza Hut line such that the Topping criteria remains the same while the formula is pulled down, and the Parlour criteria changes according to the line.

    I realize that I could achieve this goal with the SUMPRODUCT function or a macro, but the spreadsheet I'm working with needs to be quick, and rather than 5 parlours and 5 toppings, I have hundreds of parlours with hundreds more toppings, and a SUMPRODUCT setup would chug along terribly slowly.
    Attached Files Attached Files

  4. #4
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: DSUM with dynamic criteria?

    What exactly are the desired results in your sample?

  5. #5
    Registered User
    Join Date
    05-21-2007
    Posts
    79

    Re: DSUM with dynamic criteria?

    The results on the New Method tab should match the red totals on the Old Method tab for the indicated City. The main goal is to get rid of the longer list of Criteria ranges on the Old Method tab, but also avoiding SUMPRODUCTs, as they cause significant slowdown when applied on a large scale.

    My other thought was to code in a small function in VBA that would create a 2x1 array for the selected Parlour: {"Parlour";"Pizza Hut"}, a 6x1 array for the Toppings: {"Topping";"Goat Cheese"; ... ;"Marshmallow"}, and then merge them to get a 6x2 array that matches the Old Method tab criteria for the given Parlour. I'm not sure, though, what a simple function like this (which could just read in the Parlour name and have a static reference to the Toppings range) would do to the execution time compared to SUMPRODUCT.

  6. #6
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: DSUM with dynamic criteria?

    Does this work for you?

    =DSUM($B$2:$G$27,$L$3,$I$3:$I4)-SUM(M$3:M3)

    copied down

  7. #7
    Forum Guru
    Join Date
    05-24-2011
    Location
    India
    MS-Off Ver
    Office 2021
    Posts
    2,237

    Re: DSUM with dynamic criteria?

    Hello, see the attached.

    make a list of Topping items & use criteria as grey highlighted. Hope this helps.
    Attached Files Attached Files
    Regards,
    Haseeb Avarakkan

    __________________________________
    "Feedback is the breakfast of champions"

  8. #8
    Registered User
    Join Date
    05-21-2007
    Posts
    79

    Re: DSUM with dynamic criteria?

    NBVC, that solution would work in some cases, but for my purposes I think I would end up breaking it. For one, if the criteria changed it would not be immediately useable, and that is desired. I may be able to apply it in limited cases, though, to summarize my data differently, so it is still helpful!

    Haseeb A, it looks like your solution might work a little better, but I must admit, I have no idea how it works. Could you explain the logic a little for me? I'm having trouble following.

    Thanks!

  9. #9
    Forum Guru
    Join Date
    05-24-2011
    Location
    India
    MS-Off Ver
    Office 2021
    Posts
    2,237

    Re: DSUM with dynamic criteria?

    I4:I8, you have Topping items,

    Goat Cheese
    Steak
    Onion
    Mushroom
    Marshmallow

    M4:M8, Parlours.

    J5 formula,

    =$B3=INDEX(M:M,ROW())

    ROW() will give current row #, here is 5 J5. So INDEX(M:M,5) = Domino's. But when you use this N4, it calculate INDEX(M:M,ROW()). here current row is 4, so ROW() will 4, INDEX become,

    =INDEX(M:M,4) = Pizza Hut

    When you copy down, ROW() calculate, 5, 6, 7, 8.... which is Domino's, Little Caesar's, Pizza Ranch, etc...

    K5, formula

    =ISNUMBER(MATCH($C3,$I$4:$I$8,0))

    If any of the values in C3 to down contains in I4:I8 will count it. So when use in N4, it calculte

    1. If B3 to down = Value in current_Row in M:M, which is M4. Pizza Hut

    AND

    2. If C3 to down = Any of the value in I3:I8 then SUM col_D3 to down.

    Hope this help you.
    Last edited by Haseeb Avarakkan; 06-22-2011 at 04:37 PM.

  10. #10
    Registered User
    Join Date
    05-21-2007
    Posts
    79

    Re: DSUM with dynamic criteria?

    Haseeb A, I am amazed. That is a very clever and simple solution to a problem that's been dogging me all day.

    Thanks very much, it did indeed help!

  11. #11
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: DSUM with dynamic criteria?

    There is also the Pivot Table route which is efficient also....
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    01-16-2012
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003
    Posts
    1

    Re: DSUM with dynamic criteria?

    Hi Haseeb,

    I was looking for a way to use Database functions dynamically & came across this post, where you've provided an example Excel sheet doing exactly what I'm looking to achieve. My challenge is whenever I enter the edit mode of the formula & exit using a simple enter (no CSE), the formula starts showing the same value across all cells. I re-opened the file to see if you had array-entered the formula which wasn't the case. Can you please help me understand what am I doing wrong in trying to replicate the formula?

    Regards,
    Kartar

    <Update: Just realized it only happens in version 2003 (maybe lower), works fine in 2007. Is it because from 2007 onwards, MS has allowed the row() function to remain dynamic if used as part of another formula?>
    Last edited by kartarsaxena; 01-16-2012 at 10:55 AM.

  13. #13
    Forum Guru
    Join Date
    05-24-2011
    Location
    India
    MS-Off Ver
    Office 2021
    Posts
    2,237

    Re: DSUM with dynamic criteria?

    Hello Kartar, welcome to the forum!

    Please take a few minutes tom read Forum Rules. Rule # 2 says:

    2. Don't post a question in the thread of another member -- start your own. If you feel it's particularly relevant, provide a link to the other thread
    So please start your own thread

  14. #14
    Registered User
    Join Date
    01-05-2019
    Location
    Lisbon, Portugal
    MS-Off Ver
    2007
    Posts
    1

    Re: DSUM with dynamic criteria?

    Haseeb A, I came across your solution for dynamic criteria with database functions in Excel and it just what I was looking for. It's indeed a very elegant solution. Thank you very much.

+ 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