Forum Discussion
Formula to aggregate matrix spilling both rows and columns
- Feb 21, 2022
diegol81 , you are welcome.
For data only it's simpler
uHeader = UNIQUE(header, 1); uLabels = UNIQUE(labels); onlyData= MAKEARRAY( ROWS(ulabels), COLUMNS(uHeader), LAMBDA( r, c, SUM( FILTER( FILTER( data, (labels=INDEX(uLabels, r)) ), header=INDEX(uHeader, c) ) ) ) );
Many thanks for that! After the first look at your solution, I feel relieved that I wouldn't have been successful, if ever, before several days of goes at it.
Your solution is almost exactly what I was looking for. I'd like the labels to be produced by UNIQUEs on ungrouped data, so the formula should only generate the inner {12,10;9,18}. After such a robust starting point I hope I can adjust it myself.
Have a nice day!
diegol81 , you are welcome.
For data only it's simpler
uHeader = UNIQUE(header, 1);
uLabels = UNIQUE(labels);
onlyData=
MAKEARRAY( ROWS(ulabels), COLUMNS(uHeader),
LAMBDA( r, c,
SUM(
FILTER(
FILTER(
data,
(labels=INDEX(uLabels, r)) ),
header=INDEX(uHeader, c)
)
)
)
);
- diegol81Feb 21, 2022Copper Contributor
- SergeiBaklanFeb 21, 2022Diamond Contributor
diegol81 , glad to help
- diegol81Mar 24, 2022Copper Contributor
I geared the solution a bit more towards the shape I want it to have. I ended up with a single name definition, the lambda itself (actually a lambda called within another lambda), that acts a formula (SpillSum as I named it) with 3 arguments: Data, Labels, Headers.
The intention is that the formula can be used within any workbook, any number of times, without the need of defining each of the components as a name time and again. Only requisite is to define SpillSum once in each workbook.
As you'll see, it very much sticks to the general algorithm you designed. Thanks again!