4

I have five columns for which I need underlying nested values on a single row. Here is sample data I have:

ID Product Sales Manager Sales Rep Rep Status
1 Product1 Manager1 Rep1 Active
2 Product1 Manager1 Rep2 Active
3 Product1 Manager2 Rep5 Active
4 Product2 Manager1 Rep1 Active
5 Product2 Manager2 Rep5 Active
6 Product2 Manager2 Rep6 Active
7 Product3 Manager1 Rep1 Active
8 Product3 Manager1 Rep4 Active
9 Product3 Manager2 Rep6 Active

I would like to generate consolidated cells consisting of all applicable managers, their reps, and the reps status for each product listed:

...


Product1

Sales Manager: Manager1

Sales Rep: Rep1 (Active)

Sales Rep: Rep2 (Active)

Sales Manager: Manager2

Sales Rep: Rep5 (Active)


Product2

Sales Manager: Manager1

Sales Rep: Rep1 (Active)

Sales Manager: Manager2

Sales Rep: Rep5 (Active)

Sales Rep: Rep6 (Active)


Product3

Sales Manager: Manager1

Sales Rep: Rep1 (Active)

Sales Rep: Rep4 (Active)

Sales Manager: Manager2

Sales Rep: Rep6 (Active)


...

This is the formula I have been using. It can only generate each manager assigned to a product, not the reps assigned to the managers on each product, though:

...

LET(
 STAT,$E:$E,
 PROD,$B:$B,
 MAN,$C:$C,
 REP,$D:$D,
 IDE,$A:$A,
 AL,$A:$E,
 IDEA,DROP(FILTER(IDE,NOT(ISBLANK(IDE))),1),
 IDS," ID "&IDEA,
 STATUS,INDEX(STAT,MATCH(IDEA,IDE,0)),
 PRODUCT,INDEX(PROD,MATCH(IDEA,IDE,0)),
 PRODUCTS,UNIQUE(PRODUCT),
 MANAGE,INDEX(MAN,MATCH(IDEA,IDE,0)),
 MANAGES,UNIQUE(MANAGE),
 MANAGER,"
 Sales Manager:
 "&MANAGE,
 MANAGERS,UNIQUE(MANAGER),
 REPRE,INDEX(REP,MATCH(IDEA,ID,0)),
 REPRES,UNIQUE(REPRE),
 txxt,BYROW(MANAGES,LAMBDA(a,TEXTJOIN("
 ",TRUE,UNIQUE(FILTER(REPRE,MANAGE=UNIQUE(a)))))),
 REPRESENTATIVE,IF(ISNUMBER(MATCH(REPRE,{"Unspecified"},0)),"","
 Sales Representative(s):
 "&REPRE),
 hoor,VSTACK(txxt),
 MANAGING,MANAGERS&REPRESENTATIVE,
 txt,BYROW(PRODUCTS,LAMBDA(a,TEXTJOIN("
 ",TRUE,UNIQUE(FILTER(MANAGER,PRODUCT=UNIQUE(a)))))),
 hor,VSTACK(txt),
 fin,PROCESSES&"
 "&hor,
 fin
)

...

I cannot seem to get beyond a list of managers for each product:

...


Product1

Sales Manager: Manager1

Sales Manager: Manager2


Product2

Sales Manager: Manager1

Sales Manager: Manager2


Product3

Sales Manager: Manager1

Sales Manager: Manager2


...

If anyone can help me out in constructing an Excel formula (not VBA Macros or Pivot Tables), then it would be much appreciated.

Thanks!

asked Jun 2, 2025 at 21:34

6 Answers 6

4

Nested LAMBDAs

BYROW/REDUCE

=LET(data,Sheet1!B2:E10,prod_col,1,man_col,2,rep_col,3,stat_col,4,dlm,CHAR(10),
 d,IF(data="","",data),
 pc,INDEX(d,,prod_col),
 BYROW(UNIQUE(pc),LAMBDA(p,LET(
 pf,FILTER(d,pc=p),
 mc,INDEX(pf,,man_col),
 p&REDUCE("",UNIQUE(mc),LAMBDA(mm,m,LET(
 mf,FILTER(pf,mc=m),
 mm&dlm&TEXTJOIN(dlm,,"Sales Manager: "&m,
 "Sales Rep: "&INDEX(mf,,rep_col)
 &" ("&INDEX(mf,,stat_col)&")"))))))))

enter image description here

BYROW/BYROW

=LET(data,Sheet1!B2:E10,prod_col,1,man_col,2,rep_col,3,stat_col,4,dlm,CHAR(10),
 d,IF(data="","",data),
 pc,INDEX(d,,prod_col),
 BYROW(UNIQUE(pc),LAMBDA(p,LET(
 pf,FILTER(d,pc=p),
 mc,INDEX(pf,,man_col),
 TEXTJOIN(dlm,,p,BYROW(UNIQUE(mc),LAMBDA(m,LET(
 mf,FILTER(pf,mc=m),
 TEXTJOIN(dlm,,"Sales Manager: "&m,
 "Sales Rep: "&INDEX(mf,,rep_col)
 &" ("&INDEX(mf,,stat_col)&")")))))))))
answered Jun 3, 2025 at 0:10
Sign up to request clarification or add additional context in comments.

Comments

2

My formula solution is:

[G2]=LET(prod,B2:B10,man,"Sm: "&C2:C10,val,"Sr: "&D2:D10&" ("&E2:E10&")",DROP(
 REDUCE("",UNIQUE(prod),LAMBDA(a,x,VSTACK(a,
 REDUCE(x,UNIQUE(FILTER(man,prod=x)),LAMBDA(b,y,VSTACK(b,y,
 UNIQUE(FILTER(val,(prod=x)*(man=y))))))
 ))),
 1))

enter image description here

If you need a product by cell:

=LET(prod,B2:B10,man,"Sm: "&C2:C10,val,"Sr: "&D2:D10&" ("&E2:E10&")",
 MAP(UNIQUE(prod),LAMBDA(x,TEXTJOIN(CHAR(10),TRUE,
 REDUCE(x,UNIQUE(FILTER(man,prod=x)),LAMBDA(b,y,VSTACK(b,y,
 UNIQUE(FILTER(val,(prod=x)*(man=y)))))))))
)

enter image description here

answered Jun 3, 2025 at 7:55

2 Comments

I like the second version
Also check my alternative using PIVOTBY
2

Another option:

=LET(a,B2:E10,
 i,LAMBDA(x,CHOOSECOLS(a,x)),
BYROW(DROP(REDUCE(0,UNIQUE(i(1)),
 LAMBDA(b,c,
 IFNA(VSTACK(b,
 HSTACK(c,
 DROP(REDUCE(0,UNIQUE(FILTER(C1&": "&i(2),i(1)=c)),
 LAMBDA(d,e,
 HSTACK(d,
 e,
 TOROW(FILTER(D1&": "&i(3)&" ("&i(4)&")",(i(1)=c)*(i(2)=TEXTAFTER(e,": "))))))),
 ,1))),
 ""))),
 1),
 LAMBDA(r,TEXTJOIN("
",,r))))
answered Jun 3, 2025 at 20:20

8 Comments

Very creative. I like the i, but the TEXTJOIN trick is something else. No nested LET though. IYO, Is there something wrong with nesting LETs or is their benefit often insignificant (not necessarily related to this case)?
@vbasic2008 I'm not sure what you mean. The TEXTJOIN uses CHAR(10) to join the REDUCE results row wise. I used the actual CHAR(10) between "" instead of using TEXTJOIN(CHAR(10),,r) what do you mean by nested LET?
@vbasic2008 I think I see what you mean: that storing it as LET makes it calculate once and get stored in memory. But since it's inside the REDUCE, the LET will be declared/overwritten on each iteration (the result is different also for each iteration). So I don't think it's more efficient, but I may be wrong. Outside the Reduce using LET for repeated use is more efficient or simply makes the formula smaller and possibly easier to read.
I added a new row after ID #6 and...
@rotabor, quick fixed using IFNA
|
2

Another efficient way:

=LET(p,PIVOTBY(B2:B11,C1&": "&C2:C11,D1&": "&D2:D11&" ("&E2:E11&")",ARRAYTOTEXT,,0,,0),
 q,DROP(p,1),
BYROW(IF(q>"",TAKE(p,1)&"
"&SUBSTITUTE(q,", ","
"),""),LAMBDA(x,TEXTJOIN("
",,x))))
answered Jun 4, 2025 at 19:26

Comments

0

Pivot table: enter image description here Add a filter if necessary.

answered Jun 3, 2025 at 7:46

Comments

0
  1. For ease of use convert the data to table

  2. GROUPBY function - Microsoft Support, aggregating status with LAMBDA(x, ARRAYTOTEXT(UNIQUE(x))) for totals

  • -3: Grand and Subtotals at Top for 3 columns
  • DROP the first row with grand total
  1. Then formatting the grouped result based on the column values for product, manager etc.
=LET(
 grouped, DROP(
 GROUPBY(
 Table1[[Product]:[Sales Rep]],
 Table1[Rep Status],
 LAMBDA(x, ARRAYTOTEXT(UNIQUE(x))),
 0,
 -3
 ),
 1
 ),
 sm, LAMBDA(n, "Sales Manager: " & n),
 sr, LAMBDA(n, status,
 "Sales Rep: " & n & "(" & status & ")"
 ),
 BYROW(
 grouped,
 LAMBDA(r_,
 IFS(
 INDEX(r_, 1, 2) = "",
 INDEX(r_, 1, 1),
 INDEX(r_, 1, 3) = "",
 sm(INDEX(r_, 1, 2)),
 TRUE,
 sr(
 INDEX(r_, 1, 3),
 INDEX(r_, 1, 4)
 )
 )
 )
 )
)

Formula, intermediate step and result

answered Jun 5, 2025 at 17:40

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.