Reto de agrupación y pivotado: AGRUPARPOR vs ARCHIVOMAKEARRAY vs MAP

Leandro trae un reto de internet al grupo: a partir de una tabla con claves repetidas y valores, generar una tabla pivotada donde cada clave aparezca una vez y los valores se concatenen. La comunidad responde con un festival de enfoques.

Con AGRUPARPOR directo (Leo): la solución más limpia. Agrupa por clave y aplica UNIRCADENAS como función de agregación:

``
=AGRUPARPOR(
APILARV(UNICOS(claves); claves);
valores;
LAMBDA(x; UNIRCADENAS(", ";; x));;
0
)
`

Con AJUSTARFILAS + COINCIDIRX + ARCHIVOMAKEARRAY (John): enfoque completamente distinto que construye la tabla resultado celda a celda con ARCHIVOMAKEARRAY:

`
=LET(
u; UNICOS(claves);
n; MAX(CONTAR.SI(claves; u));
ARCHIVOMAKEARRAY(FILAS(u); n; LAMBDA(i; j;
SI.ND(INDICE(
FILTRAR(valores; claves = INDICE(u; i));
j
); "")
))
)
`

Con MAP + SECUENCIA + UNIRCADENAS (John): variante que genera cada fila con MAP, extrayendo los valores correspondientes a cada clave:

`
=MAP(UNICOS(claves); LAMBDA(x;
UNIRCADENAS(", ";; FILTRAR(valores; claves = x))
))
`

Con PIVOTARPOR + BUSCARX (Leo): usando PIVOTARPOR como tabla pivote y BUSCARX para rellenar las posiciones:

`
=PIVOTARPOR(claves;; valores; LAMBDA(x; UNIRCADENAS(", ";; x));; 0)
`

Cada solución tiene sus ventajas: AGRUPARPOR es la más directa, ARCHIVOMAKEARRAY ofrece control total sobre la forma del resultado, y MAP` es la más legible.

Más contenido de Excel en InflueXcel