Hstack Problem

pto160

Active Member
Joined
Feb 1, 2009
Messages
482
Office Version
  1. 365
Platform
  1. Windows
I am trying to add an extra column using the Hstack function. The third column I need to use a Text join using the delimiter ":" for the refunds who are duplicate customers and the other ones just the single refund. Here is the data.

Book1
ABC
1NameAmountVoucher
2John Smith5010020
3Paul Rudd10010021
4John Smith20010022
5Jane Smith50010023
6
7=HSTACK(UNIQUE(A2:A5),SUMIFS(B2:B5,A2:A5,UNIQUE(A2:A5)))
8
9What I want:
10NameAmountVoucher
11John Smith25010020:10022
12Paul Rudd10010021
13Jane Smith50010023
Sheet1
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
VBA Code:
=LET(u,UNIQUE(A2:A5),v,SUMIF(A2:A5,u,B2:B5),HSTACK(u,v,MAP(u,LAMBDA(x,TEXTJOIN(":",1,IF(A2:A5=x,C2:C5,""))))))
 
Upvote 0
Thank you. That works great.(y) Gotta study that MAP and lamda function more.
 
Upvote 0
This works great. Thank you so much.
How would you add the column headings to the hstack which is Name, amount and voucher?
 
Upvote 0
One way:

VBA Code:
=VSTACK({"Name","Amount","Voucher"},LET(u,UNIQUE(A2:A5),v,SUMIF(A2:A5,u,B2:B5),HSTACK(u,v,MAP(u,LAMBDA(x,TEXTJOIN(":",1,IF(A2:A5=x,C2:C5,"")))))))
 
Upvote 0
I am trying to get the unique list by customer ID, but also have the customer name in the list.
Is there a way to do this?

Book1
ABCD
1IDNameAmountVoucher
20100John Smith5010020
30200Paul Rudd10010021
40100John Smith20010022
50300Jane Smith50010023
6
7
8
9What I Like
10IDNameAmountVoucher
110100John Smith25010020:10022
120200Paul Rudd10010021
130300Jane Smith50010023
Sheet1
 
Upvote 0
VBA Code:
=VSTACK({"Name","Name","Amount","Voucher"},LET(u,UNIQUE(A2:A5),w,UNIQUE(B2:B5),v,SUMIF(A2:A5,u,C2:C5),HSTACK(u,w,v,MAP(u,LAMBDA(x,TEXTJOIN(":",1,IF(A2:A5=x,D2:D5,"")))))))
 
Upvote 0

Forum statistics

Threads
1,223,891
Messages
6,175,229
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top