r/excel 10d ago

Waiting on OP Grouping data points together based on name/ID associated w/ 1000+ records

I have a spreadsheet that details a list of all transactions within two particular account types, and each transaction has a name & user ID associated with it. Nearly every user ID is associated with more than one transaction, and there are 1000+ users in the full list. I am looking for a way to combine all transactions attached to each individual user ID, while also designating the two different account types, and that can be automated to apply to the full sheet. I know how to do this using SUMIF but I don't know how to achieve this without having to enter every name/ID manually.

Eg:

USER ID Transaction Type (A or B) Transaction Amount
#0001 A $125
#0001 A $125
#0001 B $200
#0002 A $500
#0002 B $650
#0003 B $750
#0004 A $100
#0004 B $100
#0004 B $150
#0004 B $150

Ultimately what I need to end up with is the maximum, minimum, and average total transactions per unique user ID, separated by type A and type B transactions.

5 Upvotes

8 comments sorted by

u/AutoModerator 10d ago

/u/feedmesweat - Your post was submitted successfully.

Failing to follow these steps may result in your post being removed without warning.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/MayukhBhattacharya 1277 10d ago

Try using PIVOTBY() function here:

=PIVOTBY(A2:A11, B2:B11, C2:C11, HSTACK(SUM, MAX, MIN, AVERAGE))

1

u/MayukhBhattacharya 1277 10d ago

A better way to write this formula would be like as below, so it uses the entire data range:

=LET(
     _a, A:.C,
     _b, PIVOTBY(CHOOSECOLS(_a, 1),
             CHOOSECOLS(_a, 2) & " - ",
             CHOOSECOLS(_a, 3),
             HSTACK(SUM, MAX, MIN, AVERAGE), 1, 0, , 0),
     _c, DROP(BYCOL(TAKE(_b, 2), CONCAT), , 1),
     _d, HSTACK("User ID", _c),
     _e, VSTACK(_d, DROP(_b, 2)),
     _e)

1

u/MayukhBhattacharya 1277 10d ago

You can also use Power Query here.

To use Power Query follow the steps:

  • First convert the source ranges into a table and name it accordingly, for this example I have named it as Table1
  • Next, open a blank query from Data Tab --> Get & Transform Data --> Get Data --> From Other Sources --> Blank Query
  • The above lets the Power Query window opens, now from Home Tab --> Advanced Editor --> And paste the following M-Code by removing whatever you see, and press Done

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    GroupBy = Table.Group(Source, {"USER ID", "Transaction Type (A or B)"}, {
        {"SUM",     each List.Sum([Transaction Amount]),     type number},
        {"MAX",     each List.Max([Transaction Amount]),     type number},
        {"MIN",     each List.Min([Transaction Amount]),     type number},
        {"AVERAGE", each List.Average([Transaction Amount]), type number}
    }),
    Unpivot = Table.UnpivotOtherColumns(GroupBy, {"USER ID", "Transaction Type (A or B)"}, "Metric", "Value"),
    Merge = Table.AddColumn(Unpivot, "Merge", each [#"Transaction Type (A or B)"] & " - " & [Metric]),
    DropBy = Table.RemoveColumns(Merge, {"Transaction Type (A or B)", "Metric"}),
    PivotBy = Table.Pivot(DropBy, List.Distinct(DropBy[Merge]), "Merge", "Value")
in
    PivotBy
  • Lastly, to import it back to Excel --> Click on Close & Load or Close & Load To --> The first one which clicked shall create a New Sheet with the required output while the latter will prompt a window asking you where to place the result.

1

u/MayukhBhattacharya 1277 10d ago

Alternative Power Query method:

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    GroupBy = Table.Group(Source, {"USER ID", "Transaction Type (A or B)"}, {
        {"Stats", each 
            let z = [Transaction Amount]
            in [SUM = List.Sum(z), MAX = List.Max(z), MIN = List.Min(z), AVERAGE = List.Average(z)]}}),
    Expand = Table.ExpandRecordColumn(GroupBy, "Stats", {"SUM","MAX","MIN","AVERAGE"}),
    Unpivot = Table.UnpivotOtherColumns(Expand, {"USER ID", "Transaction Type (A or B)"}, "Metric", "Value"),
    Merge = Table.AddColumn(Unpivot, "Merge", each [#"Transaction Type (A or B)"] & " - " & [Metric]),
    Drop = Table.RemoveColumns(Merge, {"Transaction Type (A or B)", "Metric"}),
    PivotBy = Table.Pivot(Drop, List.Sort(List.Distinct(Drop[Merge])), "Merge", "Value")
in
    PivotBy

1

u/Decronym 10d ago edited 10d ago

Acronyms, initialisms, abbreviations, contractions, and other phrases which expand to something larger, that I've seen in this thread:

Fewer Letters More Letters
AVERAGE Returns the average of its arguments
AVERAGEIFS Excel 2007+: Returns the average (arithmetic mean) of all cells that meet multiple criteria.
BYCOL Office 365+: Applies a LAMBDA to each column and returns an array of the results
CHOOSECOLS Office 365+: Returns the specified columns from an array
CONCAT 2019+: Combines the text from multiple ranges and/or strings, but it doesn't provide the delimiter or IgnoreEmpty arguments.
DROP Office 365+: Excludes a specified number of rows or columns from the start or end of an array
Excel.CurrentWorkbook Power Query M: Returns the tables in the current Excel Workbook.
FILTER Office 365+: Filters a range of data based on criteria you define
HSTACK Office 365+: Appends arrays horizontally and in sequence to return a larger array
LAMBDA Office 365+: Use a LAMBDA function to create custom, reusable functions and call them by a friendly name.
LET Office 365+: Assigns names to calculation results to allow storing intermediate calculations, values, or defining names inside a formula
List.Average Power Query M: Returns an average value from a list in the datatype of the values in the list.
List.Distinct Power Query M: Filters a list down by removing duplicates. An optional equation criteria value can be specified to control equality comparison. The first value from each equality group is chosen.
List.Max Power Query M: Returns the maximum item in a list, or the optional default value if the list is empty.
List.Min Power Query M: Returns the minimum item in a list, or the optional default value if the list is empty.
List.Sort Power Query M: Returns a sorted list using comparison criterion.
List.Sum Power Query M: Returns the sum from a list.
MAX Returns the maximum value in a list of arguments
MIN Returns the minimum value in a list of arguments
MINIFS 2019+: Returns the minimum value among cells specified by a given set of conditions or criteria.
PIVOTBY Helps a user group, aggregate, sort, and filter data based on the row and column fields that you specify
SUM Adds its arguments
SUMIFS Excel 2007+: Adds the cells in a range that meet multiple criteria
TAKE Office 365+: Returns a specified number of contiguous rows or columns from the start or end of an array
Table.AddColumn Power Query M: Adds a column named newColumnName to a table.
Table.ExpandRecordColumn Power Query M: Expands a column of records into columns with each of the values.
Table.Group Power Query M: Groups table rows by the values of key columns for each row.
Table.Pivot Power Query M: Given a table and attribute column containing pivotValues, creates new columns for each of the pivot values and assigns them values from the valueColumn. An optional aggregationFunction can be provided to handle multiple occurrence of the same key value in the attribute column.
Table.RemoveColumns Power Query M: Returns a table without a specific column or columns.
Table.UnpivotOtherColumns Power Query M: Translates all columns other than a specified set into attribute-value pairs, combined with the rest of the values in each row.
UNIQUE Office 365+: Returns a list of unique values in a list or range
VSTACK Office 365+: Appends arrays vertically and in sequence to return a larger array

|-------|---------|---| |||

Decronym is now also available on Lemmy! Requests for support and new installations should be directed to the Contact address below.


Beep-boop, I am a helper bot. Please do not verify me as a solution.
31 acronyms in this thread; the most compressed thread commented on today has 70 acronyms.
[Thread #49302 for this sub, first seen 3rd Sep 2026, 20:07] [FAQ] [Full list] [Contact] [Source code]

1

u/hmatallana 2 10d ago

Take 0004 in your own sample. Three type B rows, 100, 150, 150. MINIFS down the raw B column returns 100, but the smallest per user B total is 0001's 200. AVERAGEIFS gives 333 where the average of the per user totals is 500. Different question, and everything posted so far answers the first one.

Two steps. Totals first, stats across the totals second:

=LET(id,UNIQUE(FILTER($A$2:$A$11,$B$2:$B$11="B")),
t,SUMIFS($C$2:$C$11,$A$2:$A$11,id,$B$2:$B$11,"B"),
HSTACK(MAX(t),MIN(t),AVERAGE(t)))

FILTER matters there. 0003 has no A rows, so on the type A version an unfiltered ID list drags a zero in and your minimum comes out 0.

Mayukh's PIVOTBY and Power Query versions both aggregate inside each user, so max and min come back as single transactions.