+ Reply to Thread
Results 1 to 33 of 33

UDF for sum of multiple criteria in multiple columns and single criteria in multiple colum

  1. #1
    Registered User
    Join Date
    06-16-2010
    Location
    India, Pune-411006
    MS-Off Ver
    Excel 2007/2010
    Posts
    89

    UDF for sum of multiple criteria in multiple columns and single criteria in multiple colum

    Hi Experts,

    I am trying to get sum based on multiple criteria from 3 columns and single criteria from 1 columns and got the formula from “Excel Formulas & Functions” forum. However it is not working if criteria mentioned as "*" (means for all records in database).

    e.g. Earlier in sumifs function i used "*" as criteria for sum of all the records in database, have created dynamic drop-downs for selection of criteria/options for end user to view the summary of data.

    Is there any UDF to get sum based on multiple criteria in multiple columns and single criteria multiple columns......

    Please check the attached file for details.

    Any help highly appreciated.
    Attached Files Attached Files
    /Rgds,
    Ganesh Pitale

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    Make use of DSUM() function


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    06-16-2010
    Location
    India, Pune-411006
    MS-Off Ver
    Excel 2007/2010
    Posts
    89

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    I have already tried DSUM() function, however not useful for this problem.

  4. #4
    Registered User
    Join Date
    06-16-2010
    Location
    India, Pune-411006
    MS-Off Ver
    Excel 2007/2010
    Posts
    89

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    any help on above . . . .

  5. #5
    Registered User
    Join Date
    06-16-2010
    Location
    India, Pune-411006
    MS-Off Ver
    Excel 2007/2010
    Posts
    89

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    Is there any solution for the same ? ? ?

  6. #6
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    Try something like this...

    =DSUM(DATA!A1:F110,"Field 6",SUMMARY!C7:E8)

  7. #7
    Registered User
    Join Date
    06-16-2010
    Location
    India, Pune-411006
    MS-Off Ver
    Excel 2007/2010
    Posts
    89

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    1) It is not giving correct results.
    e.g. Field1 criteria selected as AIR, MAA, PNQ and Field2 criteria selected as LBU, GBU then it is showing as 688, however correct number is 16343.

    2) 1st criteria is missing or not included in the formula (Field5 criteria).

    Hence it is not workable. . .

  8. #8
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    Refer the attached file for solution
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    06-16-2010
    Location
    India, Pune-411006
    MS-Off Ver
    Excel 2007/2010
    Posts
    89

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    Hi Sixthsense,

    I am very grateful for your help and valuable time.

    I am still confused with the solution/formula as results are incorrect. Below is the difference between correct results and formula results.

    Criteria for Field 1 - AIR, MAA, PNQ
    Criteria for Field 2 - LBU, GBU
    Criteria for Field 3 - "*"

    Elements- Formula results- Correct results
    Communication Cost- 1951- 1884
    Company Cars- 945- 978
    Employee Benefits- 882- 1033
    Food & Canteen- 1932- 1888
    Housing Expense- 870- 922
    Local Data Communication- 845- 845
    Salaries and Related- 1153- 2147
    Staff Training- 1009- 1882
    Recruitment Cost- 1514- 1379
    Travel- 2100- 1333
    Sales Cost- 287- 580
    Support functional cost- 1342- 504
    Taxes- 437- 968

    Could you please look into the same . . .
    Last edited by Ganesh7299; 10-30-2013 at 05:24 AM.

  10. #10
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    Please let me know the drop down selection conditions for it…

  11. #11
    Registered User
    Join Date
    06-16-2010
    Location
    India, Pune-411006
    MS-Off Ver
    Excel 2007/2010
    Posts
    89

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    have edited earlier post

    Criteria for Field 1 - AIR, MAA, PNQ = IN
    Criteria for Field 2 - LBU, GBU = BU
    Criteria for Field 3 - "*" = All

  12. #12
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    This is the result I am getting for the said criteria’s


    C
    D
    E
    7
    Field 1
    Field 2
    Field 3
    8
    AIR
    LBU
    PNQ
    9
    MAA
    GBU
    10
    PNQ



    C
    D
    12
    Elements
    Cost
    13
    Communication Cost
    1911
    14
    Company Cars
    726
    15
    Employee Benefits
    626
    16
    Food & Canteen
    1932
    17
    Housing Expense
    870
    18
    Local Data Communication
    845
    19
    Salaries and Related
    1153
    20
    Staff Training
    943
    21
    Recruitment Cost
    1509
    22
    Travel
    1998
    23
    Sales Cost
    287
    24
    Support functional cost
    1342
    25
    Taxes
    437

  13. #13
    Registered User
    Join Date
    06-16-2010
    Location
    India, Pune-411006
    MS-Off Ver
    Excel 2007/2010
    Posts
    89

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    There is no "PNQ" in Field 3, it should be "*" (for all records).
    And if it is PNQ then results should be 0 for all because it is not exist in the data.

  14. #14
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    Here is my complete workout for your reference. Please check and tell where it is failing…


    A
    B
    C
    1
    Elements
    Amount
    Group
    2
    Communication Cost
    40
    Air/LBU
    3
    Company Cars
    219
    Air/LBU
    4
    Employee Benefits
    256
    Air/LBU
    5
    Staff Training
    66
    Air/LBU
    6
    Recruitment Cost
    5
    Air/LBU
    7
    Travel
    102
    Air/LBU
    8
    Employee Benefits
    120
    MAA/GBU
    9
    Food & Canteen
    997
    MAA/GBU
    10
    Staff Training
    780
    MAA/GBU
    11
    Recruitment Cost
    610
    MAA/GBU
    12
    Travel
    792
    MAA/GBU
    13
    Communication Cost
    1911
    PNQ
    14
    Company Cars
    726
    PNQ
    15
    Employee Benefits
    506
    PNQ
    16
    Food & Canteen
    935
    PNQ
    17
    Housing Expense
    870
    PNQ
    18
    Local Data Communication
    845
    PNQ
    19
    Salaries and Related
    1153
    PNQ
    20
    Staff Training
    163
    PNQ
    21
    Recruitment Cost
    899
    PNQ
    22
    Travel
    1206
    PNQ
    23
    Sales Cost
    287
    PNQ
    24
    Support functional cost
    1342
    PNQ
    25
    Taxes
    437
    PNQ



    A
    B
    1
    Elements
    Total
    2
    Communication Cost
    1951
    3
    Company Cars
    945
    4
    Employee Benefits
    882
    5
    Food & Canteen
    1932
    6
    Housing Expense
    870
    7
    Local Data Communication
    845
    8
    Salaries and Related
    1153
    9
    Staff Training
    1009
    10
    Recruitment Cost
    1514
    11
    Travel
    2100
    12
    Sales Cost
    287
    13
    Support functional cost
    1342
    14
    Taxes
    437

  15. #15
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c


    C
    D
    E
    7
    Field 1
    Field 2
    Field 3
    8
    AIR
    lbu
    *
    9
    MAA
    gbu
    10
    PNQ



    C
    D
    12
    Elements
    Cost
    13
    Communication Cost
    1951
    14
    Company Cars
    945
    15
    Employee Benefits
    882
    16
    Food & Canteen
    1932
    17
    Housing Expense
    870
    18
    Local Data Communication
    845
    19
    Salaries and Related
    1153
    20
    Staff Training
    1009
    21
    Recruitment Cost
    1514
    22
    Travel
    2100
    23
    Sales Cost
    287
    24
    Support functional cost
    1342
    25
    Taxes
    437

  16. #16
    Registered User
    Join Date
    06-16-2010
    Location
    India, Pune-411006
    MS-Off Ver
    Excel 2007/2010
    Posts
    89

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    I am looking for sum based on multiple criteria.

    e.g. If we select below criteria
    Field 1 -AIR, PNQ, MAA
    Field 2 - LBU, GBU
    Field 3 - "*" (all records)
    then results should be same as attached file. (please refer attached file, I have filtered data as per selected/mentioned criteria for better understanding)

    However by using DSUM() function results are totally incorrect like Communication Cost is 1884 not 1951.
    Attached Files Attached Files

  17. #17
    Registered User
    Join Date
    06-16-2010
    Location
    India, Pune-411006
    MS-Off Ver
    Excel 2007/2010
    Posts
    89

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    I am looking for sum based on multiple criteria.

    e.g. If we selected below criteria
    Field 1 -AIR, PNQ, MAA
    Field 2 - LBU, GBU
    Field 3 - "*" (all records)
    then results should be same as attached file. (please refer attached file, I have filtered data as per selected/mentioned criteria for better understanding)

    However by using DSUM() function results are totally incorrect like Communication Cost is 1884 not 1951.

  18. #18
    Registered User
    Join Date
    06-16-2010
    Location
    India, Pune-411006
    MS-Off Ver
    Excel 2007/2010
    Posts
    89

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    Hi All,

    I have created below function for this, however only one Criteria option added and wanna add 4 more criteria option in the same.

    Please Login or Register  to view this content.
    Any help highly appreciated

    Thanks

  19. #19
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    Based on you Post # 16 File

    In K9 Cell

    =SUMIFS(F:F,E:E,J9,A:A,$J$4,B:B,IF(OR($K$4={0,""}),"*",$K$4),C:C,IF(OR($L$4={0,""}),"*",$L$4))+SUMIFS(F:F,E:E,J9,A:A,$J$5,B:B,IF(OR($K$5={0,""}),"*",$K$5),C:C,IF(OR($L$5={0,""}),"*",$L$5))+SUMIFS(F:F,E:E,J9,A:A,$J$6,B:B,IF(OR($K$6={0,""}),"*",$K$6),C:C,IF(OR($L$6={0,""}),"*",$L$6))

    Drag it down...

  20. #20
    Registered User
    Join Date
    06-16-2010
    Location
    India, Pune-411006
    MS-Off Ver
    Excel 2007/2010
    Posts
    89

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    Quote Originally Posted by :) Sixthsense :) View Post
    Based on you Post # 16 File

    In K9 Cell

    =SUMIFS(F:F,E:E,J9,A:A,$J$4,B:B,IF(OR($K$4={0,""}),"*",$K$4),C:C,IF(OR($L$4={0,""}),"*",$L$4))+SUMIFS(F:F,E:E,J9,A:A,$J$5,B:B,IF(OR($K$5={0,""}),"*",$K$5),C:C,IF(OR($L$5={0,""}),"*",$L$5))+SUMIFS(F:F,E:E,J9,A:A,$J$6,B:B,IF(OR($K$6={0,""}),"*",$K$6),C:C,IF(OR($L$6={0,""}),"*",$L$6))

    Drag it down...
    Not Working . . .

  21. #21
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    Sorry boss I tried my level best to help you...

    I hope someone will take care of your query in a better way as you expect...

    Best of Luck!

  22. #22
    Registered User
    Join Date
    06-16-2010
    Location
    India, Pune-411006
    MS-Off Ver
    Excel 2007/2010
    Posts
    89

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    Thanks Bro . . .

  23. #23
    Forum Expert dredwolf's Avatar
    Join Date
    10-27-2012
    Location
    Clearwater,Canada
    MS-Off Ver
    Excel 2007
    Posts
    2,649

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    If field 3 is "*" (all records) then why use any search on it at all? (field 3 apparently does not matter, and therefore can be discarded from searching results?)

    Edit-
    IF I am mis-reading your criteria, I am sorry, but that seems to be what I am reading, and if so, then that is 1 less search criteria, which makes the formulas/functions easier, IMO

    Edit 2
    missed the VBA, now you need 5 criteria?
    Last edited by dredwolf; 11-01-2013 at 04:10 AM.
    A picture may be worth a thousand words, BUT, a sample Workbook is worth a thousand screenshots!
    -Add a File - click advanced (next to quick post), scroll to manage attachments, click, select add files, click select files, select file, click upload, when file shows up at bottom left, click done (bottom right), click submit
    -To mark thread Solved- go top of thread,click Thread Tools,click Mark as Solved
    If you received helpful response, please remember to hit the * of that post

  24. #24
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    Hi,

    I have to say that I think your set-up in this sheet leaves a lot to be desired. However, in D13 and copy down, array formula:

    =SUM(IF(ISNUMBER(MATCH("~*",$C$8:$C$10,0)),1,(ISNUMBER(MATCH(DATA!$A$2:$A$110,$C$8:$C$10,0))))*IF(ISNUMBER(MATCH("~*",$D$8:$D$10,0)),1,(ISNUMBER(MATCH(DATA!$B$2:$B$110,$D$8:$D$10,0))))*IF(ISNUMBER(MATCH("~*",$E$8:$E$10,0)),1,(ISNUMBER(MATCH(DATA!$C$2:$C$110,$E$8:$E$10,0))))*(DATA!$E$2:$E$110=C13)*DATA!$F$2:$F$110)

    Regards
    Click * below if this answer helped

    Advanced Excel Techniques: http://excelxor.com/

  25. #25
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    I could be way off, but if you have a * representing "include all" then there is no need to use that criteria for your sum, so you could replace bits in your formula like:
    (ISNUMBER(MATCH(DATA!$C$2:$C$110,$E$8:$E$10,0)))
    with
    if(or(E8="*",E9="*", E10="*"),1,(ISNUMBER(MATCH(DATA!$C$2:$C$110,$E$8:$E$10,0))))

    I think the whole formula would become (array formula):
    =SUMPRODUCT(IF(OR(C$8="*",C$9="*",C$10="*"),1,(ISNUMBER(MATCH(DATA!$A$2:$A$110,$C$8:$C$10,0))))*IF(OR(D$8="*",D$9="*",D$10="*"),1,(ISNUMBER(MATCH(DATA!$B$2:$B$110,$D$8:$D$10,0))))*IF(OR(E$8="*",E$9="*", E$10="*"),1,(ISNUMBER(MATCH(DATA!$C$2:$C$110,$E$8:$E$10,0))))*(DATA!$E$2:$E$110=C13)*DATA!$F$2:$F$110)
    in D13 and drag down.

    This gives me the following results:
    980
    701
    256
    0
    120
    845
    1387
    939
    5
    102
    0
    504
    968

    Note - this is in reference to your first attachment
    Last edited by ragulduy; 11-01-2013 at 05:59 AM.

  26. #26
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    @yudlugar

    Isn't that just precisely what I've done, though with a MATCH construction instead of your OR()?

    Regards

  27. #27
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    It is indeed, I think when I was viewing the thread I missed the second page (Hence setting mine up for the first attachment)!

  28. #28
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    Ah! Well, there's more than one way to skin a cat!

    Edit: Actually, just a thought, but notice you didn't add a tilde ~ before your asterisk - and you get different results to me - I believe this is necessary in this case?

    Regards

  29. #29
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    Edit: apologies, it doesn't appear to be required in this case.

    Your results are for field 2 without GBU included, and seem perfectly good.

    Regards

  30. #30
    Forum Expert
    Join Date
    04-22-2013
    Location
    .
    MS-Off Ver
    .
    Posts
    4,418

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    I don't think it is neccessary, =IF("S"="*",1,2) and =IF("S"="~*",1,2) both return 2 for me... I don't think you can use wildcards in an if statement.

    Ha, beat me too it again.

  31. #31
    Forum Expert XOR LX's Avatar
    Join Date
    04-18-2013
    Location
    Turin, Italy
    MS-Off Ver
    Office 365
    Posts
    7,742

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    Yes, the use of the asterisk as a wildcard doesn't seem to apply when used like this in an IF statement. Just a thought...

    And we must stop crossing!

  32. #32
    Forum Expert daddylonglegs's Avatar
    Join Date
    01-14-2006
    Location
    England
    MS-Off Ver
    2016
    Posts
    14,675

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    Assuming that any * would go in the first criteria row only (row 8) then you can use this non array formula

    =SUMPRODUCT((ISNUMBER(MATCH(DATA!A$2:A$110,C$8:C$10,0))+(C$8="*")>0)*(ISNUMBER(MATCH(DATA!B$2:B$110,D$8:D$10,0))+(D$8="*")>0)*(ISNUMBER(MATCH(DATA!C$2:C$110,E$8:E$10,0))+(E$8="*")>0)*(DATA!E$2:E$110=C13),DATA!F$2:F$110)
    Audere est facere

  33. #33
    Registered User
    Join Date
    06-16-2010
    Location
    India, Pune-411006
    MS-Off Ver
    Excel 2007/2010
    Posts
    89

    Re: UDF for sum of multiple criteria in multiple columns and single criteria in multiple c

    Hi All,

    Thanks a ton for your help on this.

    @ daddylonglegs – exactly, I was looking for the same

+ 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. Replies: 5
    Last Post: 05-25-2013, 07:12 AM
  2. [SOLVED] Sum Count of Single Criteria in Multiple Non-Adjacent columns
    By Domenic in forum Excel Formulas & Functions
    Replies: 36
    Last Post: 09-06-2005, 03:05 PM
  3. [SOLVED] Sum Count of Single Criteria in Multiple Non-Adjacent columns
    By Sam via OfficeKB.com in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  4. [SOLVED] Sum Count of Single Criteria in Multiple Non-Adjacent columns
    By Domenic in forum Excel Formulas & Functions
    Replies: 27
    Last Post: 09-06-2005, 04:05 AM
  5. [SOLVED] SUMIF with multiple criteria for multiple columns to sum a single
    By SavageMind in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2005, 11:05 AM

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