2
=LET(
Business,B6,
All_nationalities,FILTER(Data[Nationality],Data[Business]=Business),
Unique_nationalities,UNIQUE(All_nationalities),
freq,BYROW(Unique_nationalities,LAMBDA(x,COUNTIF(All_nationalities,x))),
sorted,SORTBY(Unique_nationalities,freq,-1),
INDEX(sorted,1)
)

I want to use formula above to calculate top nationalities for each of the businesses. I get #CALC! error and upon checking it comes from LAMBDA function.

I tried to split each step out to see where the error is. All_nationalities = filtered data from the table Data, for given business Unique_nationalities = filtering out unique nationalities for that business freq = should calculate total number of repeats of each unique nationality for that business

Could anyone help please? Thanks

18
  • Try this... =LET( Business, B6, All_nationalities, FILTER(Data[Nationality], Data[Business]=Business), Unique_nationalities, UNIQUE(All_nationalities), freq, MAP(Unique_nationalities, LAMBDA(x, COUNTIF(All_nationalities, x))), sorted, SORTBY(Unique_nationalities, freq, -1), INDEX(sorted, 1) ) Commented Oct 13 at 11:25
  • Hi @SiddharthRout - tried earlier MAP alongside BYROW - both giving the same #CALC! error Commented Oct 13 at 11:27
  • 2
    COUNTIF does, I believe, require a range as its first argument, whereas All_nationalities is an array, and not a range. Commented Oct 13 at 11:53
  • 1
    Sample data |----------|-------------| | HU | Lebanese | | HU | Pakistani | | SH | Kuwaiti | | SH | Turkish | | SH | Turkish | | HU | Pakistani | | DU | Chinese | | DU | Chinese | | DU | Chinese | | HU | Pakistani | | SH | Turkish | | SH | Indian | | SH | Indian | | SH | Indian | | SH | Indian | | HU | Sri Lankan | | HU | Sri Lankan | | DU | Taiwanese | | DU | Pakistani | | DU | Pakistani | Commented Oct 13 at 13:45
  • 1
    Expected result Top Nationalities by business shortname would be: DU = Chinese; Hu = Pakistani; SH = Indian. But with my formula I can't work out how to do it Commented Oct 13 at 13:50

2 Answers 2

3

If I understand you correctly (what I am not sure about) then you can use this formula:

=GROUPBY(
    Data[Nationality],
    Data[Nationality],
    COUNTA,
    0,
    0,
    -2,
    Data[Business] = B6
)
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much, Ike. Sorted now. '=INDEX(SORT(GROUPBY(Data[Nationality], Data[Nationality], COUNTA, 0, 0, 1, Data[Business] = B18),2,-1),1)'
The 6th parameter of GROUPBY can be set to -2 (instead of 1): then the result will be sorted descending by the second column ... no extra SORTneeded - I update the answer
3

Another alternative-

=LET(x,Table1[Nationality],y,HSTACK(x,COUNTIFS(x,x)),SORT(UNIQUE(FILTER(y,Table1[Business Unit]=F1)),2,-1))

enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.