Table manipulations using dynamic arrays

sharshra

Active Member
Joined
Mar 20, 2013
Messages
404
Office Version
  1. 365
I have to derive an output as shown in the 'desired output' table based on a 'source table' using the logic given below. I got partially correct result, but there are few issues. Can the experts help please?

Source table has the id, ph, name & dept. The output table should have the ids for the combination of name & dept in ph 1 & 2. I see that the result is incorrect when same name is in multiple dept. It just counts the name in all ph & duplicate the result for dept.

For example, trtr should have 3 rows in the output with different ids. But all ids of trtr are duplicated against depts c, l & a. Cells with incorrect output are marked in pink.

Source table:
excel problems.xlsx
BCDE
21idphnamedept
2281kjkjc
23711yuyul
24392kjkja
25541trtrc
26231nbc
2761nbc
28911trtrl
2921trtra
3072nbc
31642kjkja
Sheet8


Desired output:
excel problems.xlsx
HIJKLM
21deptnameph 1 countph1ph2 countph2
22lyuyu171
23ltrtr191
24ckjkj18
25ctrtr254
26cnb223, 617
27akjkj239, 64
28atrtr12
Sheet8


Actual output:
excel problems.xlsx
PQRSTU
21deptnameph 1 countph1ph2 countph2
22lyuyu171
23ltrtr354, 91, 2
24ckjkj18239, 64
25ctrtr354, 91, 2
26cnb223, 617
27akjkj18239, 64
28atrtr354, 91, 2
Sheet8
Cell Formulas
RangeFormula
P22:U28P22=LET( all, $B$22:$E$31, name, CHOOSECOLS(all, 3), ph, CHOOSECOLS(all, 2), dptName, SORT(UNIQUE(CHOOSECOLS(all, 4,3)),,-1), idDptName, LAMBDA(phs, IFERROR(CHOOSECOLS(MAP(dptName, LAMBDA(x, TEXTJOIN(", ", ,UNIQUE(CHOOSECOLS(FILTER(all, (name=x)*(ph=phs)),1))))),2),"")), idDptName1, idDptName(1), idDptName2, idDptName(2), idDptNameCount, LAMBDA(phs, IFERROR(CHOOSECOLS(MAP(dptName, LAMBDA(x, TEXTJOIN(", ", ,ROWS(UNIQUE(CHOOSECOLS(FILTER(all, (name=x)*(ph=phs)),1)))))),2),"")), idDptNameCount1, idDptNameCount(1), idDptNameCount2, idDptNameCount(2), HSTACK(dptName,idDptNameCount1,idDptName1, idDptNameCount2,idDptName2))
Dynamic array formulas.
 
Glad we could help & thanks for the feedback.
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

Forum statistics

Threads
1,224,812
Messages
6,181,089
Members
453,021
Latest member
Justyna P

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