You can use an array approach that spill the entire result at once and extracts directly the numbers to multiply (m
) from the header. It assumes the number can be extracted on each cell looking backward for the first ending parenthesis, then the first opening parenthesis, via TEXTBEFORE
and TEXTAFTER
functions. On cell B7
use the following formula:
=LET(in, B2:F6, h, B1:F1, m, 1*TEXTAFTER(TEXTBEFORE(h,")",-1),"("),
cnts, MAP(SEQUENCE(,COLUMNS(m)), LAMBDA(i,SUM(N(INDEX(in,,i)="x")))),m*cnts)
Here is the output:

If you want to replace 0
s with an empty string as you have in your screenshot, then replace m*cnts
as follows: IF(m*cnts=0,"", m*cnts)
.
If you asked yourself why I used MAP
instead of BYCOL
?, which is a more intuitive option. You can check the answers to the following questions:
- How to make lambda function working on excel365? my answer and from @EEM.
- TEXTSPLIT combined with BYROW returns an unexpected result when using an array of strings as input answer from @JvdV.
Anyway, you can use it via Implicit intersection operator (@) as follows:
=LET(in, B2:F6, h, B1:F1, m, 1*TEXTAFTER(TEXTBEFORE(h,")",-1),"("),
cnts, BYCOL(SEQUENCE(,COLUMNS(m)), LAMBDA(i,SUM(N(INDEX(in,,@i)="x")))),m*cnts)