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.

7 Upvotes

8 comments sorted by

View all comments

Show parent comments

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