Question

I've been trying to figure out how to have part of an excel formula calculated 'normally' and the other calculated as an array formula.

Specifically I am trying to define the rank of an item where i am retrieving the value then applying the RANK.EQ formula on a dynamically created subset of certain array, filtered based on another column.

The current code is RANK.EQ(INDEX(RANKING_COLUMN,MATCH(TARGET_CELL,TARGET_COLUMN,0)),IF(FILTER_COLUMN=FILTER_CELL,RANKING_COLUMN,0),1) where INDEX(RANKING_COLUMN,MATCH(TARGET_CELL,TARGET_COLUMN,0)) should be static and IF(FILTER_COLUMN=FILTER_CELL,RANKING_COLUMN,0) is defining the dynamic array.

I was hoping to use the array constant syntax {} to exclude the required static value from the array calculation, but formulas are not allowed.

Any help would be welcome on this.

Thank you

Was it helpful?

Solution

I'm not sure why you want a "partial" array formula, is it for efficiency purposes? AFAIK Excel requires you to "array enter" all formulas where any part of the formula requires array entry, but I assume there's no particular loss of efficiency because of that when evaluating the non-array parts.

In your formula you seem to be ranking descending (with lowest value ranked 1), is that your intent? If so then I don't think you want to return 0 for the FALSE part of your dynamic IF function because the zeroes would potentially affect the rank.

In any case COUNTIF can be used to simulate RANK.EQ and so COUNTIFS can be used to simulate RANK.EQ with a condition - neither of those functions needs "array entry" so you should be able to use this formula:

=COUNTIFS(RANKING_COLUMN,"<"&INDEX(RANKING_COLUMN,MATCH(TARGET_CELL, TARGET_COLUMN,0)),FILTER_COLUMN,FILTER_CELL)+1

That formula counts values in the ranking column which are lower than your static value and when the Filter column also meets the Filter Cell criterion. That effectively gives you a "descending rank with condition", although you need to add 1, otherwise the top rank is zero.

Edit: addressing your comment - I assume you want the next item in rank for that specific filter? In your MATCH function the comparison will produce an array of TRUE/FALSE values so the "lookup value" for MATCH needs to be TRUE.....not 1, but even then the second COUNTIFS will include results for every row, so you could get a match for the wrong filter category. This version should fix that [note extra criteria in 2nd COUNTIFS]

=MATCH(TRUE,COUNTIFS(RANKING_COLUMN,"<"&INDEX(RANKING_COLUMN,MATCH(TARGET_CELL, TARGET_COLUMN,0)),FILTER_COLUMN,FILTER_CELL)+1=COUNTIFS(RANKING_COLUMN,"<"&RANKING_COLUMN,FILTER_COLUMN,FILTER_COLUMN,FILTER_COLUMN,FILTER_CELL),0)

....and if you want to retrieve a value from another column you'll need INDEX too........but note that if there are duplicates then there may be gaps in the RANKS (as per normal behaviour of RANK function) so "next rank" may not exist

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top