简体   繁体   English

如何在 Excel 的 MMULT 查找中找到最后一个匹配项?

[英]How can I find the LAST match in a MMULT lookup in Excel?

I am a song leader at our church, and I am using a spreadsheet to track how recently we have used each hymn in our hymnbook.我是我们教会的歌曲领袖,我正在使用电子表格来跟踪我们最近使用赞美诗书中的每首赞美诗的情况。 (In an effort to give some rotation to the songs we sing each week.) (为了让我们每周唱的歌曲有一些轮播。)

Using some very helpful guides on Exceljet, I was able to construct a formula that does almost exactly what I want... It tells me how many weeks ago we used each song in our hymnbook.在 Exceljet 上使用一些非常有用的指南,我能够构建一个几乎完全符合我想要的公式......它告诉我多少周前我们使用了我们赞美诗书中的每首歌。 The problem is that it currently only shows me the FIRST time we used the song, not the LAST or most recent time, which is what I am really wanting to do.问题是它目前只显示我们第一次使用这首歌的时间,而不是最后一次或最近一次,这是我真正想要做的。

The key issue I am stuck on is how to get the last entry from a MMULT() formula.我遇到的关键问题是如何从MMULT()公式中获取最后一个条目。 A simplified example is shown below... I want to return the last date from column A where example hymn #15 is listed in columns B , C , or D .下面显示了一个简化的示例...我想返回A列中的最后一个日期,其中示例赞美诗 #15 列在BCD列中。

My current formula does a great job of getting the first matching row (Row 3) but does not give me the last row (Row 5).我当前的公式在获取第一个匹配行(第 3 行)方面做得很好,但没有给我最后一行(第 5 行)。

{=INDEX(ServiceDate,MATCH(1,MMULT(--(HymnNumbers=F2),TRANSPOSE(COLUMN(HymnNumbers)^0)),0))}

( ServiceDate = A:A and HymnNumbers = B:D ) ( ServiceDate = A:AHymnNumbers = B:D )

在此处输入图片说明

Yes, I realize that there are other ways to find the last match, with MATCH and LOOKUP if I build a very complicated expression that searches for the last match in each column individually and finds the largest date value, but performance is also an issue with the size of the data in the actual spreadsheet I am using.是的,我意识到还有其他方法可以找到最后一个匹配项,如果我构建一个非常复杂的表达式来单独搜索每列中的最后一个匹配项并找到最大的日期值,则使用MATCHLOOKUP ,但性能也是一个问题我正在使用的实际电子表格中数据的大小。

Is there is something simple that I can tweak in my current MMULT function to return the last match instead of the first one?我可以在当前的MMULT函数中调整一些简单的东西来返回最后一个匹配而不是第一个匹配吗?

If dates are sorted you can reduce your formula to如果日期已排序,您可以将公式减少到

=INDEX(A:A,AGGREGATE(14,6,ROW(A:A)/(B:D=F2),1))

在此处输入图片说明

Here's a longer formula that will return the last match.这是一个较长的公式,将返回最后一场比赛。 I'm not sure if it fits your definition of "very complicated".我不确定它是否符合您对“非常复杂”的定义。 This version is longer since it does not use the latest version of excel.此版本较长,因为它不使用最新版本的 excel。

=INDEX(A1:A10,MATCH(LARGE(MMULT(--(B1:D10=F2),TRANSPOSE(COLUMN(B1:D10)^0))*ROW(A1:A10),1),MMULT(--(B1:D10=F2),TRANSPOSE(COLUMN(B1:D10)^0))*ROW(A1:A10),0))

在此处输入图片说明

If you have Office365 and dynamic formulas then you can use simply below formula.如果你有Office365和动态公式,那么你可以简单地使用下面的公式。

=MAX(FILTER(A2:A9,(B2:B9=F2)+(C2:C9=F2)+(D2:D9=F2)))

在此处输入图片说明

If you do not have Office365 then try below Array formula.如果您没有Office365尝试以下数组公式。

=MAX(IF(B2:B9=F2,A2:A9,""),IF(C2:C9=F2,A2:A9,""),IF(D2:D9=F2,A2:A9,""))

Press CTRL + SHIFT + ENTER to evaluate the formula as it is an array formula.CTRL + SHIFT + ENTER来计算公式,因为它是一个数组公式。

Your formula can be amended as follows...您的公式可以修改如下...

=INDEX(ServiceDate,MATCH(2,1/MMULT(--(HymnNumbers=F2),TRANSPOSE(COLUMN(HymnNumbers))^0)))

However, you can avoid using MMULT as follows...但是,您可以避免使用 MMULT,如下所示...

=INDEX(ServiceDate,LARGE(IF(HymnNumbers=F2,ROW(ServiceDate)-MIN(ROW(ServiceDate))+1),1))

Note that both these formulas need to be confirmed with CONTROL+SHIFT+ENTER.请注意,这两个公式都需要使用 CONTROL+SHIFT+ENTER 进行确认。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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