简体   繁体   中英

Excel Array Formula Multiple Conditions Empty String

I have the columns

  • B4 (This Sheet Column B) = Part#
  • Database A = Date
  • Database C = Part#
  • Database AA = Text Comment

With the following formula, I want to look, for the comment field with the most recent date that is not empty and return that value. In case an error is returned, I just want an empty string returned:

     =IFERROR(INDEX(Database!AA$2:$AA$5000;MATCH(MAX(IF(""<>
Database!$AA$2:$AA$5000;IF(B4=Database!$C$2:$C$5000;Database!$A$2:$A$5000)))
&B4;Database!$A$2:$A$5000&Database!$C$2:$C$5000;0));"")

The problem however is, that if I only check for either the most recent date, or un-empty cells, the latest row is returned. If, however I mix the two conditions I get blank cells accross the board.

Anybody an idea on how to combine those two conditions with array formulas? (I know, VBA would make my life much easier here, but I must not use anything but self-updating formulas)

This can be done without CSE using INDEX with the AGGREGATE¹ function providing the cyclic processing much as SUMPRODUCT does without entering as an array formula. Like an array formula, the number of rows processed should be minimized to avoid calculation lag.

AGGREGATE is first used to find the maximum date based on the part number and non-blank comment; a form of pseudo-MAXIF. That value is used in a second AGGREGATE to return a row number to an INDEX of the comments column that also matches the part number and non-blank comment.

In C13 as a standard formula,

=INDEX(AA:AA, AGGREGATE(15, 6, ROW(A$1:INDEX(A:A, MATCH(1E+99,A:A )))/((C:C=B13)*(A:A=AGGREGATE(14, 6, A$1:INDEX(A:A, MATCH(1E+99,A:A ))/((C$1:INDEX(C:C, MATCH(1E+99,A:A ))=B13)*SIGN(LEN(AA$1:INDEX(AA:AA, MATCH(1E+99,A:A ))))), 1))*SIGN(LEN(AA$1:INDEX(AA:AA, MATCH(1E+99,A:A ))))), 1))

max_date_two_conditions


¹ The AGGREGATE function was introduced with Excel 2010. It is not available in earlier versions.

² Array formulas need to be finalized with Ctrl + Shift + Enter↵ . If entered correctly, Excel with wrap the formula in braces (eg { and } ). You do not type the braces in yourself. Once entered into the first cell correctly, they can be filled or copied down or right just like any other formula. Try and reduce your full-column references to ranges more closely representing the extents of your actual data. Array formulas chew up calculation cycles logarithmically so it is good practise to narrow the referenced ranges to a minimum. See Guidelines and examples of array formulas for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM