Simple Example of Using THUNK in Excel
- V E Meganathan
- 2 days ago
- 1 min read
The input data includes columns for Year, Winner, and Runners-up.

The goal is to calculate the count of Winners and Runners-up for each Country.
Method-1:
=LET(a,B2:C22,REDUCE(,MAP(UNIQUE(TOCOL(a)),LAMBDA(x,LAMBDA(z,LAMBDA(z))(HSTACK(x,BYCOL(a,LAMBDA(y,COUNTIF(y,x))))))),LAMBDA(c,w,VSTACK(IFERROR(c(),c),w()))))
Here, BYCOL is evaluated first, and then the result is thunked within the MAP function.
Method-2:
=LET(a,B2:C22,REDUCE(,MAP(UNIQUE(TOCOL(a)),LAMBDA(x,LAMBDA(HSTACK(x,BYCOL(a,LAMBDA(y,COUNTIF(y,x))))))),LAMBDA(c,w,VSTACK(IFERROR(c(),c),w()))))
In this approach, BYCOL is thunked inside MAP and evaluated during the REDUCE function. I learned this from Jon Wittwer.
Alternatively, the task can be done using the REDUCE function without thunking, as shown below:
=LET(a,B2:C22,DROP(REDUCE("",UNIQUE(TOCOL(a)),LAMBDA(x,y,VSTACK(x,HSTACK(y,COUNTIF(B2:B22,y),COUNTIF(C2:C22,y))))),1))





Comments