简体   繁体   English

查找包含特定年份的第一个日期

[英]Find first date that contains a specific year

I'm trying to build a MATCH formula (or a similar one) that returns the position of the first value (date) within a range that matches a specific year. 我正在尝试建立一个MATCH公式(或类似的公式),该公式返回与特定年份匹配的范围内的第一个值(日期)的位置。

For example, if I have a list of dates, like this: 例如,如果我有一个日期列表,像这样:

      A
1 12-31-2014
2 11-30-2015
3 12-29-2016
4 12-30-2017

For the value 2016, it should return 3. 对于值2016,它应返回3。

MATCH(2016,A:A,0) doesn't work, since it's not an exact match. MATCH(2016,A:A,0)不起作用,因为它不完全匹配。 I can't use any aux columns either nor modify the dates. 我也不能使用任何辅助列,也不能修改日期。

Any ideas? 有任何想法吗?

Are you allowed to use array formulas? 您可以使用数组公式吗? If so, it may be as simple as this: 如果是这样,它可能像这样简单:

=IFERROR(MATCH(2016,YEAR($A$1:$A$4),0),"No Match")

Remember to commit the answer using Ctrl + Shift + Enter , since it'll be an array. 请记住使用Ctrl + Shift + Enter提交答案,因为它将是一个数组。

You'll want to change the references within the YEAR function to match your range. 您需要在YEAR函数中更改引用以匹配您的范围。 By using 0 as your [match_type] parameter, you're going to get the first value in the list that has a year of 2016 . 通过使用0作为您的[match_type]参数,您将获得具有2016年的列表中的第一个值。

For real dates, try, 对于真实日期,请尝试,

=aggregate(15, 6, row($1:$999)/(year(a$1:a$999)=2016), 1)
'return the date with index as,
=index(a:a, aggregate(15, 6, row($1:$999)/(year(a$1:a$999)=2016), 1))

If they are in ascending order you could use, 如果它们以升序排列,则可以使用,

=MATCH(42369, A:A)+1
=index(a:a, MATCH(42369, A:A)+1)

For a list of strings that look like dates try, 有关看起来像日期的字符串列表,请尝试,

=MATCH("*2016", A:A, 0)
=index(a:a, MATCH("*2016", A:A, 0))

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

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