Few problems with dynamic arrays

sharshra

Active Member
Joined
Mar 20, 2013
Messages
391
Office Version
  1. 365
I´m using dynamic arrays to get the required output as mentioned below. There are few problems to be solved with this. Can the experts help please?

Source table contains name, dept & case 3. From this, I need a table which shows for each name, number of cases & dept. I´m getting partially correct output, but there are few problems to be fixed / improvements to be done.

1. For each name, I´m getting the all dept & cases together. I want to make them separate. For example, name abc should have a line each for finance & sales with count & cases also shown separately.

2a. When there is no name, count is shown calculation error. How to fix it?

2b. When there is no name, I want to show 'no name´ instead of blank. When I use IF to get 'no name', it resulting in calculation error. How to fix it? Refer the last table.
Excel Formula:
IF(UNIQUE(name)="", "no name",UNIQUE(name))

3. In the formula, only difference between nDept & caseName is the array name in FILTER. I want to create a reusable LAMBDA function within the formula & reuse. I don´t want to create thru name manager. How can it be done?

Source table:
excel problems.xlsx
BCD
2namedeptcase #
3abcfinance2
4abcfinance32
5deffinance32
6efgfinance11
7bcdhr8
8hr60
9hr55
10cdeprocurement76
11procurement46
12abcsales93
13defsales45a
14mnosecurity37
filter


Desired output:
excel problems.xlsx
FGHI
2deptnamecountcases
3financeabc22, 32
4financedef132
5financeefg111
6hrbcd18
7hrno name255, 60
8procurementcde176
9procurementno name146
10salesabc193
11salesdef145a
12securitymno137
filter


Dynamic array formula used:
excel problems.xlsx
KLMN
2namedeptcasescount
3abcfinance, sales2, 32, 933
4deffinance, sales32, 45a2
5efgfinance111
6bcdhr81
7hr, procurement60, 55, 46#CALC!
8cdeprocurement761
9mnosecurity371
filter
Cell Formulas
RangeFormula
K2:N9K2=LET( all, $B$3:$D$20, name, $B$3:$B$20, dept, $C$3:$C$20, case, $D$3:$D$20, uName, UNIQUE(name&""), nDept, MAP(uName, LAMBDA(x, TEXTJOIN(", ",,UNIQUE(FILTER(dept,name=x))))), caseName, MAP(uName, LAMBDA(x, TEXTJOIN(", ", ,UNIQUE(FILTER(case, name=x))))), cCount, MAP(uName, LAMBDA(x, ROWS(FILTER(case, (name=x)*(name<>""))))), heading, HSTACK({"name"}, {"dept"}, {"cases"}, {"count"}), output, VSTACK(heading, HSTACK(uName, nDept, caseName,cCount)), output)
Dynamic array formulas.


Calculation when 'no name' inserted for blank names:
excel problems.xlsx
KLMN
2namedeptcasescount
3abcfinance, sales2, 32, 933
4deffinance, sales32, 45a2
5efgfinance111
6bcdhr81
7no name#CALC!#CALC!#CALC!
8cdeprocurement761
9mnosecurity371
filter
Cell Formulas
RangeFormula
K2:N9K2=LET( all, $B$3:$D$20, name, $B$3:$B$20, dept, $C$3:$C$20, case, $D$3:$D$20, uName, IF(UNIQUE(name)="", "no name",UNIQUE(name)), nDept, MAP(uName, LAMBDA(x, TEXTJOIN(", ",,UNIQUE(FILTER(dept,name=x))))), caseName, MAP(uName, LAMBDA(x, TEXTJOIN(", ", ,UNIQUE(FILTER(case, name=x))))), cCount, MAP(uName, LAMBDA(x, ROWS(FILTER(case, (name=x)*(name<>""))))), heading, HSTACK({"name"}, {"dept"}, {"cases"}, {"count"}), output, VSTACK(heading, HSTACK(uName, nDept, caseName,cCount)), output)
Dynamic array formulas.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Hello, this seems like a perfect job for the new GROUPBY function, e.g. something like:

Excel Formula:
=LET(
a,HSTACK(C2:C13,B2:B13),
b,IF(a="","no name",a),
c,GROUPBY(b,D2:D13,COUNTA,,0),
d,GROUPBY(b,D2:D13,ARRAYTOTEXT,,0),
HSTACK(c,CHOOSECOLS(d,3)))
 
Upvote 1
It seems that it is possible to use multiple functions at once within GROUPBY which makes the formula even shorter:

Excel Formula:
=LET(
a,HSTACK(C2:C13,B2:B13),
b,IF(a="","no name",a),
DROP(GROUPBY(b,D2:D13,HSTACK(COUNTA,ARRAYTOTEXT),0,0),1))
 
Upvote 0
Thanks, @hagia_sofia. Is GROUPBY available in O365 version? I´m getting an error. It is not recognizing GROUPBY :oops:

excel problems.xlsx
K
13#NAME?
filter
Cell Formulas
RangeFormula
K13K13=LET( a,HSTACK(C2:C13,B2:B13), b,IF(a="","no name",a), c,GROUPBY(b,D2:D13,COUNTA,,0), d,GROUPBY(b,D2:D13,ARRAYTOTEXT,,0), HSTACK(c,CHOOSECOLS(d,3)))
 
Upvote 0
It might not be (not sure about the calendar but GROUPBY and PIVOTBY recently dropped into my Excel) - try to update your 365.
 
Upvote 0
Oops....the end users will have to use the spreadsheet with their current O365 only. Can the desired output be obtained with current version of O365 which doesn´t support GROUPBY?
 
Upvote 0
After a check it seems that GROUPBY should now be available for all users.
That post is quite recent and says that it is now available to all users on the "Current Channel". The Monthly Enterprise Channel should get it soon but those on the "Semi-Annual Enterprise Channel" are likely to have a bit of a wait.

Current Channel

1728824570206.png

All Channels

1728824499161.png
 
Upvote 0
OK. Good to know that it will be available soon :) Unfortunately, I & the end users of the spreadsheet will need this now. Any suggestions on completing the formula will be of great help.
 
Upvote 0
Hello again, many thanks to @Alex Blakenburg for the correction and sorry for the inconveniece, please test the following:

Excel Formula:
=LET(
a,IF(B2:C13="","no name",B2:C13),
b,UNIQUE(a),
c,BYROW(a,LAMBDA(x,CONCAT(x))),
d,BYROW(b,LAMBDA(x,CONCAT(x))),
e,MAP(d,LAMBDA(x,SUM(--(c=x)))),
f,DROP(REDUCE("",d,LAMBDA(x,y,VSTACK(x,TEXTJOIN(", ",,SORT(FILTER(D2:D13,c=y)))))),1),
HSTACK(CHOOSECOLS(b,2,1),e,f))
 
Upvote 1
Solution

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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