Just for testing purpose, I have the following formula showing different scenarios at the same time via HSTACK:
=LET(item, "A", colA, A2:A7, colB, B2:B7, ux, UNIQUE(colA),
noMapOut, MAXIFS(colB, colA, item),
mapOut1, MAP(ux, LAMBDA(item, MAXIFS(B2:B7, A2:A7, item))),
mapOut2, MAP(ux, LAMBDA(item, MAXIFS(colB, colA, item))),
HSTACK(noMapOut, mapOut1, IFERROR(mapOut2, "#CALC!"))
)
and here is the output:
From the result:
noMapOut: Returns the max of the groupA, as expected. This scenario uses the names defined in theLETfunction. It demonstrateMAXIFScan work with names representing ranges defined in theLETfunction, when it is not invoked insideMAP.mapOut1: It works. This scenario doesn't use the names defined inLETmapOut2: Returns#CALC!error (I encapsulated it withIFERRORbecause otherwise it returns#CALC!for the entireHSTACKoutput). This scenario uses the same ranges as inmapOut1, just referring to them as names defined in theLETfunction. This is my real scenario, the other ones are just for testing purpose and to be able to isolate the problem.
Therefore the issue seems to be a combination of factors. The unexpected error appears when 1) using MAXIFS inside 2) MAP and 3) names from LET function are used representing the ranges.
Is there any explanation for that? Am I doing something wrong or it is just another Excel bug?
Here is the input data:
| Group | Values |
|---|---|
| A | 10 |
| A | 20 |
| B | 10 |
| B | 5 |
| C | 30 |
| C | 20 |
Note: I am not looking for a workaround, just trying to understand unexpected result of mapOut2 scenario. The workaround to get the expected result can be mapOut1 scenario or just using FILTER instead of MAXIFS:
=LET(rng, A2:B7, colA, INDEX(rng,,1), colB, INDEX(rng,,2), colAUx, UNIQUE(colA),
MAP(colAUx, LAMBDA(item, FILTER(colB, (colA=item)
* (colB = MAX(FILTER(colB, colA=item))))
))
)
It returns the expected result:
20
10
30
