+ Reply to Thread
Results 1 to 13 of 13

How to aggregate data based on multiple criteria?

Hybrid View

  1. #1
    Registered User
    Join Date
    09-28-2023
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    6

    How to aggregate data based on multiple criteria?

    Hi All

    I've a table for inventory tracking where parts coming from oversease needs to be tracked based on estimated monthly arrivals. Parts are spread across multiple order numbers and what I am trying to do is develop a report in which collate the part numbers such a way that for each individual part number, its aggregate total in transit is shown under a calendar month. The delivery schedule is well into 2024. But a few problems I am not able to figure out are that:

    (i) Same part number under same order number is being shipped out over multiple shipments, so how do I make an aggregate for these arrivals and put them under separate calendar months according to their ETA?

    (ii) The file contains historical data as well i.e parts which have recently been delivered. I am not able to come up with a logic to exclude these delivered parts from the count of incoming inventory.

    The source file gets updated maybe couple of times a month and because most of the deliveries are well into the future, projection would not change that much in my report.

    I've been trying various combination of vlookup, count, countif, IF statements but unable to come up with any formulae that could achieve the results. Of course a crude way would be to just filter the date based on required parameters, get the figures and put them manually in a calendar based table but I really want to see if some bit of automation can be constructed for this task. Would highly appreciate any assistance.
    Attached Files Attached Files

  2. #2
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: How to aggregate data based on multiple criteria?

    Your description of what you WANT to see is vague, and you have not mocked it up. So this is a guess of what you want..

    Formula: copy to clipboard
    =LET(
    A,A2:F59,
    B,UNIQUE(FILTER(INDEX(A,,4),INDEX(A,,5)="Yes")),
    C,TRANSPOSE(UNIQUE(TEXT(SORT(FILTER(INDEX(A,,6),INDEX(A,,3)>0)),"mmm yyyy"))),
    D,DROP(REDUCE("",C,LAMBDA(y,z,HSTACK(y,BYROW(B,LAMBDA(x,SUMPRODUCT((INDEX(A,,4)=x)*(TEXT(INDEX(A,,6),"mmm yyyy")=z)*INDEX(A,,3))))))),,1),
    VSTACK(HSTACK("Code",C),HSTACK(B,D)))
    Attached Files Attached Files
    Glenn




    None of us get paid for helping you... we do this for fun. So DON'T FORGET to say "Thank You" to all who have freely given some of their time to help YOU

  3. #3
    Registered User
    Join Date
    09-28-2023
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    6

    Re: How to aggregate data based on multiple criteria?

    Quote Originally Posted by Glenn Kennedy View Post
    Your description of what you WANT to see is vague, and you have not mocked it up. So this is a guess of what you want..

    Formula: copy to clipboard
    =LET(
    A,A2:F59,
    B,UNIQUE(FILTER(INDEX(A,,4),INDEX(A,,5)="Yes")),
    C,TRANSPOSE(UNIQUE(TEXT(SORT(FILTER(INDEX(A,,6),INDEX(A,,3)>0)),"mmm yyyy"))),
    D,DROP(REDUCE("",C,LAMBDA(y,z,HSTACK(y,BYROW(B,LAMBDA(x,SUMPRODUCT((INDEX(A,,4)=x)*(TEXT(INDEX(A,,6),"mmm yyyy")=z)*INDEX(A,,3))))))),,1),
    VSTACK(HSTACK("Code",C),HSTACK(B,D)))
    Hi Glenn

    Thank you so much for your support, it is what I was looking for. I tried but failed to understand your solution as I wanted to see if I can use it to further manipulate the data in some more creative ways. While I understand some stuff like unique, index etc but rest flew way above my head. Is there a way you can dumb it down for a freshie like myself? As an additional exercise oI was trying to sum and put the total for each part number under respective calendar month regardless of transit status. But those formulas like Drop, Reduce, Hstack totally threw me off.

  4. #4
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: How to aggregate data based on multiple criteria?

    PS. I changed the formula in column C to return the NUMBER zero, not TEXT.

  5. #5
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,188

    Re: How to aggregate data based on multiple criteria?

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however it has been brought to our attention that the same query has been posted on one or more other forums and you have not told us about this. You are required to do so. Cross-posts are allowed but you must provide a link to your posts on other sites.

    Please see Forum Rule #7 about cross-posting and adjust accordingly. Read this to understand why we (and other sites like us) consider this to be important: https://excelguru.ca/a-message-to-forum-cross-posters/

    (Note: this requirement is not optional. As you are new here, I shall do it for you ONCE ONLY: https://www.mrexcel.com/board/thread...teria.1245987/)
    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. It's a universal courtesy.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    NB:
    as a Moderator, I never accept friendship requests.
    Forum Rules (updated August 2023): please read them here.

  6. #6
    Forum Moderator Glenn Kennedy's Avatar
    Join Date
    07-08-2012
    Location
    Digital Nomad... occasionally based in Ireland.
    MS-Off Ver
    O365 (PC) V 2406
    Posts
    44,662

    Re: How to aggregate data based on multiple criteria?

    How annoying is that!!

  7. #7
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (both in England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2505 (Windows 11 Home 24H2 64-bit)
    Posts
    91,188

    Re: How to aggregate data based on multiple criteria?

    OP obviously hasn't read the rules. Two rules violated in one fell swoop - not a great start!

  8. #8
    Registered User
    Join Date
    09-28-2023
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    6

    Re: How to aggregate data based on multiple criteria?

    My sincere apologies to both of you, yes I did not take time to read the forum rules and it's on me. Been in a tough spot after having spent quite a bit of time trying to solve this problem on my own and kept running into a wall, but no excuse, please accept my apologies.

  9. #9
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,755

    Re: How to aggregate data based on multiple criteria?

    If this works for you since you did not provide a sample solution

    Excel 2016 (Windows) 64 bit
    H
    I
    J
    1
    PCB Model Month Year Quantity
    2
    11T40S4000-3D.007 June 2023
    3
    3
    12T40S5000-5D.003 August 2023
    10
    4
    11T40S4000-3D.007 October 2023
    9
    5
    11T40S4000-3D.007 August 2023
    2
    6
    11T40S4000-3D.007 July 2023
    2
    7
    11T40S4000-3D.007 September 2023
    2
    8
    12T40S5000-5D.003 October 2023
    9
    9
    11T40S4000-3D.007 November 2023
    6
    10
    11T40S4000-3D.007 December 2023
    2
    11
    13T40S7000-7D.005 January 2024
    3
    12
    12T40S5000-5D.003 March 2024
    7
    13
    14T40S8000-8D.006 April 2024
    8
    14
    13T40S7000-7D.005 April 2024
    3
    15
    13T40S7000-7D.005 May 2024
    4
    16
    12T40S5000-5D.003 May 2024
    23
    17
    15T40S9000-9D.007 May 2024
    4
    18
    12T40S5000-5D.003 June 2024
    1
    19
    16T40S4000-4D.001 June 2024
    4
    20
    13T40S7000-7D.005 June 2024
    3
    21
    16T40S4000-4D.001 July 2024
    4
    22
    12T40S5000-5D.003 July 2024
    6
    23
    11T40S4000-3D.007 July 2024
    3
    24
    16T40S4000-4D.001 August 2024
    2
    25
    17T40S3000-4D.002 March 2024
    7
    26
    11T40S4000-3D.007 October 2024
    3
    27
    13T40S7000-7D.005 November 2024
    4
    28
    17T40S3000-4D.002 September 2024
    8
    Sheet: Sheet1

    With Power Query

    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Required ETA", type date}}),
        #"Inserted Month Name" = Table.AddColumn(#"Changed Type", "Month Name", each Date.MonthName([Required ETA]), type text),
        #"Inserted Year" = Table.AddColumn(#"Inserted Month Name", "Year", each Date.Year([Required ETA]), Int64.Type),
        #"Inserted Merged Column" = Table.AddColumn(#"Inserted Year", "Month Year", each Text.Combine({[Month Name], Text.From([Year], "en-US")}, " "), type text),
        #"Grouped Rows" = Table.Group(#"Inserted Merged Column", {"PCB Model", "Month Year"}, {{"Quantity", each List.Sum([Qty]), type number}})
    in
        #"Grouped Rows"
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  10. #10
    Registered User
    Join Date
    09-28-2023
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    6

    Re: How to aggregate data based on multiple criteria?

    Duplicate.....
    Last edited by Jurez; 09-28-2023 at 11:14 PM.

  11. #11
    Registered User
    Join Date
    09-28-2023
    Location
    Chicago, IL
    MS-Off Ver
    Office 365
    Posts
    6

    Re: How to aggregate data based on multiple criteria?

    Quote Originally Posted by alansidman View Post
    If this works for you since you did not provide a sample solution

    Excel 2016 (Windows) 64 bit
    H
    I
    J
    1
    PCB Model Month Year Quantity
    2
    11T40S4000-3D.007 June 2023
    3
    3
    12T40S5000-5D.003 August 2023
    10
    4
    11T40S4000-3D.007 October 2023
    9
    5
    11T40S4000-3D.007 August 2023
    2
    6
    11T40S4000-3D.007 July 2023
    2
    7
    11T40S4000-3D.007 September 2023
    2
    8
    12T40S5000-5D.003 October 2023
    9
    9
    11T40S4000-3D.007 November 2023
    6
    10
    11T40S4000-3D.007 December 2023
    2
    11
    13T40S7000-7D.005 January 2024
    3
    12
    12T40S5000-5D.003 March 2024
    7
    13
    14T40S8000-8D.006 April 2024
    8
    14
    13T40S7000-7D.005 April 2024
    3
    15
    13T40S7000-7D.005 May 2024
    4
    16
    12T40S5000-5D.003 May 2024
    23
    17
    15T40S9000-9D.007 May 2024
    4
    18
    12T40S5000-5D.003 June 2024
    1
    19
    16T40S4000-4D.001 June 2024
    4
    20
    13T40S7000-7D.005 June 2024
    3
    21
    16T40S4000-4D.001 July 2024
    4
    22
    12T40S5000-5D.003 July 2024
    6
    23
    11T40S4000-3D.007 July 2024
    3
    24
    16T40S4000-4D.001 August 2024
    2
    25
    17T40S3000-4D.002 March 2024
    7
    26
    11T40S4000-3D.007 October 2024
    3
    27
    13T40S7000-7D.005 November 2024
    4
    28
    17T40S3000-4D.002 September 2024
    8
    Sheet: Sheet1

    With Power Query

    let
        Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Required ETA", type date}}),
        #"Inserted Month Name" = Table.AddColumn(#"Changed Type", "Month Name", each Date.MonthName([Required ETA]), type text),
        #"Inserted Year" = Table.AddColumn(#"Inserted Month Name", "Year", each Date.Year([Required ETA]), Int64.Type),
        #"Inserted Merged Column" = Table.AddColumn(#"Inserted Year", "Month Year", each Text.Combine({[Month Name], Text.From([Year], "en-US")}, " "), type text),
        #"Grouped Rows" = Table.Group(#"Inserted Merged Column", {"PCB Model", "Month Year"}, {{"Quantity", each List.Sum([Qty]), type number}})
    in
        #"Grouped Rows"


    Wow! That was my next step for which I posted question to Kevin as well. You folks here all geniuses!

    How do I load this data? I started Power BI in my Excel and loaded the source file that I am working with. For next step, do I put that above Power Query in the formula bar?

  12. #12
    Forum Guru HansDouwe's Avatar
    Join Date
    06-21-2022
    Location
    Nederland
    MS-Off Ver
    365 V2403 (Build 17330.20000)
    Posts
    6,466

    Re: How to aggregate data based on multiple criteria?

    Here is another solution with a formula (returns the same data as Glenn's formula in the lay-out of Alan's solution):

    Please try in H1 and custom format column I as "mmmm yyyy":
    =LET(
      a,A2:F999,
      p,INDEX(a,,4),
      q,INDEX(a,,3),
      e,EOMONTH(--INDEX(a,,6),0),
      b,SORT(UNIQUE(FILTER(HSTACK(p,e),q)),2),
      VSTACK(HSTACK("PCB Model","Required ETA","Qty In transit"),HSTACK(b,MAP(INDEX(b,,1),INDEX(b,,2),LAMBDA(x,y,SUM(q*(p=x)*(e=y)))))))
    Attached Files Attached Files
    Last edited by HansDouwe; 09-29-2023 at 12:53 AM.

  13. #13
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2505 Win 11
    Posts
    24,755

    Re: How to aggregate data based on multiple criteria?

    Power Query is a free AddIn for Excel 2010 and 2013, and is built-in functionality from Excel 2016 onwards (where it is referred to as "Get & Transform Data").

    It is a powerful yet simple way of getting, changing and using data from a broad variety of sources, creating steps which may be easily repeated and refreshed. I strongly recommend learning how to use Power Query - it's among the most powerful functionalities of Excel.

    - Follow this link to learn how to install Power Query in Excel 2010 / 2013.

    - Follow this link for an introduction to Power Query functionality.

    - Follow this link for a video which demonstrates how to use Power Query code provided.

+ 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. Use Aggregate Function With Multiple Criteria
    By Dal123 in forum Excel General
    Replies: 11
    Last Post: 07-17-2023, 07:50 AM
  2. [SOLVED] Index+Aggregate - Need to exclude based on criteria
    By MiserableShake0 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-20-2022, 12:14 AM
  3. [SOLVED] Using Aggregate, Indexed to return Multiple Returns, but Multiple Criteria?
    By JOHN_ANDERSON in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 06-04-2022, 07:59 AM
  4. [SOLVED] Match Multiple Criteria INDEX & Aggregate
    By remyte in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-26-2019, 09:15 AM
  5. Aggregate multiple values into one cell based on multiple criteria using VBA
    By jwestover1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-04-2013, 01:17 PM
  6. how to calculate aggregate numbers based on a certain criteria
    By Sheki in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-06-2007, 01:47 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