I am trying to create a formula that shows a list of Top 20 staff names based on a grouped count. Futhermore, I am trying to dynamically apply a filter to said list.
The data is being taken from the following table NoCstNoAcr
, that consists of a list of users, their respective company and branch.
I can successfully show the top 20 usernames based on the file count – but when I try to apply a branch filter (i.e., show the top 20 usernames in a specific branch grouped by file count), the formula returns #CALC!
due to nested arrays.
Below is my code:
=LET(
branchFilter; D33;
NoCstNoAcrHeaders; NoCstNoAcr[#Headers];
branchIndex; MATCH("Branch Code"; NoCstNoAcrHeaders; 0);
operatorIndex; MATCH("Operator Full Name"; NoCstNoAcrHeaders; 0);
filteredData; IF(ISBLANK(branchFilter);
NoCstNoAcr;
FILTER(NoCstNoAcr; INDEX(NoCstNoAcr[Branch Code];;)=branchFilter));
operatorNames; UNIQUE(INDEX(filteredData;;operatorIndex));
fileCounts; MAP(operatorNames; LAMBDA(name; COUNTIF(INDEX(filteredData;;operatorIndex); name)));
sortedData; SORTBY(HSTACK(operatorNames; fileCounts); fileCounts; -1);
TAKE(sortedData; 20)
)
The branch filter is residing in cell D33
.
Can someone help me understand why this error occurs and how to fix the formula so it works correctly when a branch filter is applied?