![](/img/trans.png)
[英]How to make a list of values from an array (2 columns) based on one criteria?
[英]Excel Match Multiple Criteria Lookup Array: Find columns that contains all values from a list and return the columns position in the array
我似乎無法解決這個可能很簡單的 excel function 問題(不是 VBA)。 在 Microsoft Excel 數組中:我想找到一個包含列表(數字)中所有值的列,並在數組(數值)中返回該列 position。
Col1 | Col2 | Col3 | Col4 | Col5 |
---|---|---|---|---|
4 | 8 | 4 | 7 | 4 |
1 | 4 | 2 | 9 | 10 |
9 | 3 | 2 | 8 | 8 |
10 | 3 | 2 | 6 | 10 |
10 | 5 | 8 | 4 | 9 |
5 | 9 | 1 | 9 | 5 |
5 | 5 | 5 | 6 | 4 |
4 | 1 | 5 | 1 | 2 |
值列表:
val1 | val2 | val3 | val4 |
---|---|---|---|
1 | 4 | 6 | 9 |
有效列#: 4
數組(表): arrayTable1
使用 (CTR+SHIFT+ENTER) 測試的公式(函數):
{=SMALL(IF(($A$2:$E$9)*($A$12:$A$15),COLUMN($A$2:$E$9)-COLUMN($A$2)+1),ROWS($1:$5))}
生成的公式: #N/A
在此先感謝您的幫助。
編輯以闡明公式要求/附加信息:
1: Using Microsoft Excel 2010 version. Some newer functions not available.
Using Microsoft Excel 2010 version. Some newer functions not available.
2: Can use functions like: v/h/lookup,small/large,index,match,countif/countifs,sumproduct,mode,mmult,transpose,aggregate,indirect,etc.
3: Actual data set for array (table) is hundreds of columns and growing. This means I need a formula that can check the whole array AND return columns# (4,etc.) that matches (contains) all the values in the list (criteria).
Actual data set for array (table) is hundreds of columns and growing. This means I need a formula that can check the whole array AND return columns# (4,etc.) that matches (contains) all the values in the list (criteria).
4: Brainstorming
我看到了其他一些具有基本查找概念的答案,但它們不包括同時搜索整個表數組。
公式概念1: {=SMALL(IF(INDEX(IFERROR(--($A$2:$E$9=$A$12:$A$15),0),,),COLUMN($A$2:$E$9)-COLUMN($A$2)+1),ROW($1:$5))}
生成的公式: incorrect results (possibly first value column location only)
公式概念2: {=IFERROR(MODE.MULT(IF((INDEX((((($A$2:$E$9=$A$12)*COLUMN($A$2:$E$9))+(($A$2:$E$9=$A$13)*COLUMN($A$2:$E$9))+(($A$2:$E$9=$A$14)*COLUMN($A$2:$E$9))+(($A$2:$E$9=$A$15)*COLUMN($A$2:$E$9)))),,)<>0),COLUMN($A$2:$E$9))),"")}
生成的公式: 4
*This formula is not a solution to original problem and will only work under specific instances to solve a specific problem. I will explain more in an answer below.
*This formula is not a solution to original problem and will only work under specific instances to solve a specific problem. I will explain more in an answer below.
Possible relevant links to other answers?:
參考:can-match-function-in-an-array-formula-to-return-multiple-matches
參考:excel-match-multiple-criteria
參考:excel-modal-value-in-list-with-if-function
參考:can-excels-index-function-return-array
編輯: For our purposes @EEM solution is currently the easiest to implement, validate, and maintain. Thanks for all responses.
For our purposes @EEM solution is currently the easiest to implement, validate, and maintain. Thanks for all responses.
在 Office 365 中,我們可以使用一些數組公式,結合 IFS 語句來實現這一點(這里數據在 A1:C9 中,數組在 H1:K1 中):
=IFS(MIN(--COUNTIFS(A1:A9,H1:K1)),"Col1",
MIN(--COUNTIFS(B1:B9,H1:K1)),"Col2",
MIN(--COUNTIFS(C1:C9,H1:K1)),"Col3",
MIN(--COUNTIFS(D1:D9,H1:K1)),"Col4",
MIN(--COUNTIFS(E1:E9,H1:K1)),"Col5",
TRUE, "None")
其工作方式是計算第一列的 COUNTIFS,然后將其轉換為 boolean(0 或 1),並找到最小值以檢查它們是否都存在。 如果不是,則檢查第二列,依此類推。
親切的問候
MTwem
我很接近,但不確定如何過濾掉不匹配的內容。
使用表格使公式更容易並命名數據表格范圍。
=MATCH(OFFSET(ValuesList,0,COLUMN()-Column(ResultsTable),1,1),OFFSET(DataTable,0,ROW()-ROW([val1]),ROWS(DataTable),1),0)
=IF(ISNA(SUM(ResultsTable[@[val1]:[val4]])),"",ROW()-ROW(ResultsTable)+1)
好的,現在ResultsTable[MatchCols]
是一個數組,每列一個值,如果該列不完全匹配,則每個值要么是“”,要么是列號,如果它確實包含 ValuesList 中的所有值,在您的示例中, ResultsTable[MatchCols]
應該是 {"","","",4,"","","",""}
對於其他人,@suntech1 對此進行了嘗試並提供了一張圖片。
如果要匹配的值數量不定,那很好,但您需要在表中創建足夠多的列。 ValuesList 和 ResultsTable 之間的列名不必匹配。 (實際上,ValuesList 可能只是一個數組而不是一個表。)此外,您可以將 MatchCols 列公式更改為對COUNT(ValuesList)
敏感,以便在 ResultsTable 沒有足夠的列時引發錯誤並忽略如果 ResultsTable 有太多列,則額外列。
您提到了要匹配的值列表。 如果您需要匹配任意數量的值列表,那么......好吧......您應該在問題中提到這一點。 :-P
這沒有給你什么是你要求的,因為DataTable[MatchCols]
是你要求在數組中穿插""
值的東西。
這能讓你足夠接近嗎?
有沒有人知道如何在 Excel 2010中獲取數組DataTable[MatchCols]
,即數字和""
,並過濾掉空字符串以便它只返回數字?
該解決方案使用幫助單元和TEXTJOIN function 。
假設Data
和值列表分別位於[D2:H10]
和[B13:B17]
。
此公式驗證每列中是否存在值,在D14
中輸入並復制到[D14:H17]
:
= IFERROR( MATCH( $B14, D$3:D$10, 0 )^0, "" )
此公式驗證存在所有值的列,輸入D18
並復制到[D18:H18]
:
= IF( SUM(D14:D17)=COUNT($B$14:$B$17), COLUMNS($D$18:D$18), "" )
這個公式合並了各列的結果,輸入[D20]
= TEXTJOIN( ",",TRUE, $D$18:$H$18 )
此方法僅返回至少包含一次 List 中每個值的列。
編輯 - 結合第一個和第二個公式的 FormulaArray
此FormulaArray
驗證每列中是否存在值並返回存在所有值的列,在D18
中輸入並復制到[D18:H18]
:
= IF( SUM( IFERROR( MATCH( $B$14:$B$17, D$3:D$10, 0 )^0, 0 ) )
= COUNT($B$14:$B$17), COLUMNS($D$18:N$18), "" )
輸入FormulaArray
同時按住ctrl + shift + enter ,如果輸入正確,公式將包含在{
和}
中。
編輯 - Excel 2010 公式僅顯示符合標准的列(每個列在一個單獨的單元格中)
在[D22]
中輸入此公式,然后復制到[E22:N22]
:
= IFERROR( INDEX( $D$18:$N$18,
AGGREGATE( 15, 6, COLUMN($18:$18) / ( $D$18:$N$18 <> "" ),
COLUMNS($D$18:D$18) ) ), TEXT(,) )
這不是我正在尋找的解決方案,但此解決方案可能會幫助其他人或可能導致其他人為原始問題提供解決方案。 我在研究時通過反復試驗發現。
公式: {=IFERROR(MODE.MULT(IF((INDEX((((($A$2:$E$9=$A$12)*COLUMN($A$2:$E$9))+(($A$2:$E$9=$A$13)*COLUMN($A$2:$E$9))+(($A$2:$E$9=$A$14)*COLUMN($A$2:$E$9))+(($A$2:$E$9=$A$15)*COLUMN($A$2:$E$9)))),,)<>0),COLUMN($A$2:$E$9))),"")}
生成的公式: 4 *Formula works under certain instances.
注意事項:
1: Need unique values in columns for this solution (no duplicates in columns).
2: This formula provides column positions that has the max modal matches (partial list matches & complete list matches can result per column).
在測試中,這意味着如果這些列與每列的最大匹配項匹配,則每列會產生部分匹配。
3: If duplicates in columns this can result in the duplicate values being counted towards the max match per column.
因此,如果在一列中有 [4,2,2,2] 並且有 [2,4] 作為您的列表,那么該列將導致 4 個匹配項。 因此,如果您的用例需要這樣的結果,那么這可能對您有用。
如果其他人可以解釋為什么這樣做或提出適合原始問題的解決方案,請這樣做。
謝謝, 尚德1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.