Feb 03 2024 02:05 PM
I need to create attendance lists for events where several hundred tickets are sold. Some people buy a single ticket while others buy multiple tickets. Is there a formula I can use so that (in this example) the first table becomes the second table:
Last Name | Name | No. seats | Seats |
Goplik | Bert | 1 | L15 |
Goplik | Bert | 1 | L16 |
Heep | Judith | 1 | C16 |
Heep | Judith | 1 | C17 |
Park | Mary | 1 | E6 |
Booth | Peter | 1 | K10 |
Booth | Peter | 1 | K11 |
Holmes | Sally | 1 | G19 |
Last Name | Name | No. seats | Seats |
Goplik | Bert | 2 | L15 L16 |
Heep | Judith | 2 | C16 C17 |
Park | Mary | 1 | E6 |
Booth | Peter | 2 | K10 K11 |
Holmes | Sally | 1 | G19 |
Feb 03 2024 02:56 PM
@Randy340 you could use a pivot table or power query to do this or using modern formulas you can use:
=LET(
in, A2:D9,
names, UNIQUE(TAKE(in, , 2)),
seats, BYROW(
names,
LAMBDA(r,
LET(
tix, FILTER(in, MMULT(--(TAKE(in, , 2) = r), {1; 1}), ""),
SUM(tix) & ", " & TEXTJOIN(" ", , TAKE(tix, , -1))
)
)
),
HSTACK(names, TEXTBEFORE(seats, ","), TEXTAFTER(seats, ", "))
)
Feb 03 2024 04:15 PM - edited Feb 03 2024 04:19 PM
In case you are looking for a Power Query solution (very easy to follow) use the code below:
let
Source = Excel.CurrentWorkbook(){[Name="tblRaw"]}[Content],
#"Group rows" = Table.Group(Source, {"Last Name", " Name"}, {{"No. Seats", each List.Sum([No. seats]), type number}, {"Seats", each Text.Combine([Seats],"#(lf)")}})
in
#"Group rows"
Just copy and paste the code into the PQ advanced editor. I named the source table tblRaw. Adjust the name for your use case and load the data back to Excel. All done!
Feb 03 2024 06:09 PM
@Randy340 Here is one more way of utilizing the modern excel functions like GROUPBY() although one needs to use MS365 with the Beta Channel (Office Insiders) enabled. Personally, I would have gone using POWER QUERY which makes it way easier, simpler and more importantly time saving, effortless as well can handle quite a lot of data as far I know. Perhaps here is my attempt using the said function.
=LET(
_GroupByLastName_Name, GROUPBY(A2:B9,HSTACK(C2:D9),HSTACK(SUM,ARRAYTOTEXT),0,0),
_DroppingTempHeader, DROP(_GroupByLastName_Name,1),
_ReplacingCommasWithLineFeeds, SUBSTITUTE(_DroppingTempHeader,", ",CHAR(10)),
VSTACK(A1:D1,_ReplacingCommasWithLineFeeds))
Note: Variable _ReplacingCommasWithLineFeeds is unnecessary here, since the required output for Seats column uses line feeds to join them hence added to substitute the commas with line feeds, but if you are satisfied with the use commas, then can remove that part.
Feb 03 2024 08:21 PM
Feb 03 2024 09:29 PM
Hi @Randy340 ,
Follow the process to apply PQ:
Feb 03 2024 10:30 PM