简体   繁体   English

将日期的月份和年份与日期行匹配

[英]Matching a month and year of a date to a row of dates

I want to match a start date by month and year (regardless of the day) to a corresponding date that is a column header and return the column number of said date.我想按月和年(无论是哪一天)将开始日期与相应的日期(即 header 列)匹配,并返回所述日期的列号。


  Name    Start Date   1/7/2015   2/9/2016   4/25/2016  
 ------- ------------ ---------- ---------- ----------- 
  Steve   1/8/2015     100             350         700  
  Amy     2/2/2016     N/A             250         412  

The code I have tried is:我试过的代码是:

MATCH(1,(MONTH(B2)=MONTH($C$1:$E$1))*(YEAR(B2)=YEAR($C$1:$E$1)),0)

The response is "#Value" when it should return "1" for Steve and "2" for Amy.当它应该为史蒂夫返回“1”和为艾米返回“2”时,响应为“#Value”。

As per my comment;根据我的评论; this is an array formula.这是一个数组公式。 So either:所以要么:

  • Confirm the formula through holding Ctrl + Shift and only then press Enter通过按住Ctrl + Shift确认公式,然后按Enter
  • Add in an additional INDEX , like so:添加一个额外的INDEX ,如下所示:

     =MATCH(1,INDEX((MONTH(B2)=MONTH($C$1:$E$1))*(YEAR(B2)=YEAR($C$1:$E$1)),),0)

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

相关问题 在单独的单元格中指定月份和年份后,如何创建一个月内所有日期的行? - How can I create a row of all dates in a month after specifying the month and year in a separate cell? 日期过滤器-月和年 - Date Filter - Month & Year Grouping a column with dates and times (by date, month, and year) in an Excel Pivot Table using Java Apache POI - Grouping a column with dates and times (by date, month, and year) in an Excel Pivot Table using Java Apache POI 按月过滤,如果日期是一年前? - Filter by month and if a date was a year ago? 按月和年对“日期”列进行排序 - Sort Date column by month and year 如果月份和年份与该行中的dd / mm / yyyy格式的日期单元格匹配,则返回该行中的所有单元格值 - Return all cell values in a row if Month & Year match a dd/mm/yyyy formatted date cell in that row 年和月下的索引和匹配列 - Index and matching column under year and month Excel中的公式:匹配年份和日期 - Formula in Excel: Matching Year and Date DAX计算年初至今-上个月的年份(年份更改) - DAX Calculate Year To Date - Year to Previous Month (year change) Excel公式可将日期标记为(1,0),从现在开始到过去1年的几个月。如过去3个月,过去6个月和年初至今 - Excel formula to fetch dates as a flag (1,0) for months from now into past 1 yr.As in Past 3month,Past 6 months and Year to date
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM