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.
 
Alternatively, with a combination of Power Query and Power Pivot.

Book1
ABCDEFGH
1namedeptcase #deptnameCount of case #Cases
2abcfinance2financeabc22, 32
3abcfinance32def132
4deffinance32efg111
5efgfinance11hrbcd18
6bcdhr8No Name260, 55
7hr60procurementcde176
8hr55No Name146
9cdeprocurement76salesabc193
10procurement46def145a
11abcsales93securitymno137
12defsales45a
13mnosecurity37
Sheet1


firstly, need to populate null values with No Name in Power query
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Replaced Value" = Table.ReplaceValue(Source,null,"No Name",Replacer.ReplaceValue,{"name"})
in
    #"Replaced Value"

then close and load to the Data Model.

In Power Pivot
Create a Measure
then create your PT
 

Attachments

  • Screenshot 2024-10-13 103716.png
    Screenshot 2024-10-13 103716.png
    20.8 KB · Views: 2
  • Screenshot 2024-10-13 103641.png
    Screenshot 2024-10-13 103641.png
    21.8 KB · Views: 1
Upvote 1

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
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))
Thanks, @hagia_sofia :) It works almost except 2 issues.
1. Header has the number instead of heading of 'count'.
2. The last row for security is missing.

excel problems.xlsx
KLMN
13deptname1case #
14financeabc22, 32
15financedef132
16financeefg111
17hrbcd18
18hrno name255, 60
19procurementcde176
20procurementno name146
21salesabc193
22salesdef145a
filter
Cell Formulas
RangeFormula
K13:N22K13=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))
Dynamic array formulas.
 
Upvote 0
Thanks for the feedback! It seems like you selected the headers and not the last row - so the question is whether headers should also be part of the formula?
 
Upvote 0
Just wanted to check on the 3rd question in my first thread. I would like to create a reusable LAMBDA function within the formula.

For example, in the following lines from the current formula, only difference is the input array to BYROW function. It´s a candidate for a reusable LAMBDA function. I have created LAMBDA function thru name manager. But, I would like to create reusable LAMBDA function within the formula. Tried few but failed. I know it is simple but I´m making some mistakes. Can the experts advise please?

Excel Formula:
c,BYROW(a,LAMBDA(x,CONCAT(x))),
d,BYROW(b,LAMBDA(x,CONCAT(x))),
 
Upvote 0
Just wanted to check on the 3rd question in my first thread. I would like to create a reusable LAMBDA function within the formula.

For example, in the following lines from the current formula, only difference is the input array to BYROW function. It´s a candidate for a reusable LAMBDA function. I have created LAMBDA function thru name manager. But, I would like to create reusable LAMBDA function within the formula. Tried few but failed. I know it is simple but I´m making some mistakes. Can the experts advise please?

Excel Formula:
c,BYROW(a,LAMBDA(x,CONCAT(x))),
d,BYROW(b,LAMBDA(x,CONCAT(x))),

It's not entirely clear what you mean by "within the formula". And why not thru name manager? If you define a custom LAMBDA function in name manager, it can be reused throughout the workbook. If you define it within LET, it can only be reused within that one formula.

Since you don't appear to have GROUPBY or PIVOTBY yet, I'm guessing that you don't have the new eta-lambdas either (e.g. =BYROW(array,CONCAT)). Is this what you want to create? Your own customized eta-lambdas, to be used in the [function] argument of BYROW?

To do this within LET, simply define a variable for the LAMBDA function. For example:

Excel Formula:
=LET(
    ...
    λ, LAMBDA(x,CONCAT(x)),
    c, BYROW(a,λ),
    d, BYROW(b,λ),
    ...
)

However, I still think it would be better to define it in name manager and name it CONCATλ, for example. Then you could reuse it throughout the workbook with =BYROW(array,CONCATλ).

If that's not what you meant, please provide an example of how you intend to write it (even if it doesn't work), so we can better determine what your end goal is.
 
Upvote 0

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