简体   繁体   中英

INDEX/MATCH with multiple criteria

Need assistance with an Excel formula.

I am trying to get a summary of a range. I have been playing with the Match, Index, Countif functions and can create a list of unique dates and then using a vlookup to return the persons name.

I need something to take the persons name into account so if the same date appears for 2 people, it shows as 2 different lines in the output.

Please see table below - A&B is the input, D&E is what I can currently get, G&H is the output I want.

Thanks in advance.

       A        B       C       D       E      F     G         H
1   13/01/15  RYAN           13/01/15  RYAN        13/01/15   RYAN
2   13/01/15  RYAN           14/01/15  RYAN        14/01/15   RYAN
3   14/01/15  RYAN           15/01/15  RYAN        14/01/15   FRANK
4   14/01/15  RYAN                                 15/01/15   RYAN
5   14/01/15  RYAN
6   14/01/15  RYAN
7   14/01/15  FRANK
8   14/01/15  FRANK
9   14/01/15  FRANK
10  15/01/15  RYAN
11  15/01/15  RYAN

All knowledge I have of Excel in self taught thanks the forums like stackoverflow so any help is greatly appreciated.

Much the easiest way to achieve this is with a PivotTable. Add labels to Columns A and B (say Date and Name) then select A:B, INSERT, Tables - PivotTable, chose where in Existing Sheet or New Sheet and drag Date and then Name (below) into ROWS.

Reformat as desired.

The style of array formula I prefer requires that there be an unused cell directly above the first formula to avoid circular references. This unused cell can be used as a column header label.

The array formulas¹ used in D2:E2 are,

=IFERROR(INDEX(A:A, MATCH(0, COUNTIFS(D$1:D1,A$1:INDEX(A:A, MATCH(1E+99, A:A))&"",
                                      E$1:E1,B$1:INDEX(B:B, MATCH(1E+99, A:A))&""), 0)), "")
=IFERROR(INDEX(B:B, MATCH(0, COUNTIFS(D$1:D1,A$1:INDEX(A:A, MATCH(1E+99, A:A))&"",
                                      E$1:E1,B$1:INDEX(B:B, MATCH(1E+99, A:A))&""), 0)), "")

Fill down as necessary. These array formulas have their most active lookup ranges dynamically truncated at the row containing the last date in column A to cut calculation cycles down to the minimum necessary.

two_column_unique

I have added an extra entry for Frank at the bottom of the list of your sample data to further demonstrate the double unique lookup.


¹ 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.

With helper columns this could be achieved without any array formulas. The idea is to get first a concatenation of date and name, then get only the line number of the first occurrence of date&name in the list, get those line numbers without duplicates and finally get the INDEXes of those line numbers from A:A and B:B.

在此处输入图片说明

Formulas:

D1:D13  =A1&B1
E1:E13  =IF($D1<>"",MATCH($D1,$D:$D,0),"empty")
F1      =MIN($E:$E)
F2:F13  =LARGE($E:$E,COUNTIF($E:$E,">"&$F1))
H1:H13  =INDEX($A:$A,$F1)
I1:I13  =INDEX($B:$B,$F1)

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