简体   繁体   English

Excel-如何获取日期是否为星期几?

[英]Excel - how to get if a date is a specific day of the week?

I have a spreadsheet that tracks average file processing times over the course of a month. 我有一个电子表格,可以跟踪一个月内的平均文件处理时间。 One of the macros and stats that we like to pull, is performance on Mondays (as the files are a little built up over the weekend). 我们希望提取的宏和统计信息之一是星期一的性能(因为文件在周末积累了一些)。 The spreadsheet is organized into columns by weekdays of the month: 电子表格按每月的工作日分为几列:

Excel示例

The dates are formatted MM/DD/YYYY, so I would think Excel has a date function that it can determine weekday based on that date value. 日期格式为MM / DD / YYYY,因此我认为Excel具有日期功能,可以根据该日期值确定工作日。

Currently, I just have to manually tell the Macro which columns are Mondays, like so: 目前,我只需要手动告诉宏,哪几列是星期一,就像这样:

 =AVERAGE(B20,G20,L20,Q20)

So, instead of manually, how would I get the average over the range of say, B20 to V20 , only if the day of the week is Monday (the date cells are in row 1, so B1 to V1 )? 因此,不是手动地,仅当星期几是星期一(日期单元格在第1行,所以B1V1 )时,如何才能得到B20V20范围内的平均值?

To determine the weekday of a date in EXCEL use the =WEEKDAY() formula, which evaluates as 1 (Sunday) to 7 (Saturday) 要确定EXCEL中日期的工作日,请使用=WEEKDAY()公式,该公式的计算结果为1(星期日)至7(星期六)

eg If A1 contains 12/31/2016 (or 31/12/2016 if you're from where I'm from), the formual =WEEKDAY(A1) would evaluate to 7 (indicating that the last day of 2016 was a Saturday) 例如,如果A1包含12/31/2016(如果您来自我所在的地方,则为31/12/2016),则正式的=WEEKDAY(A1) WEEKDAY =WEEKDAY(A1)取值为7(表示2016年的最后一天是星期六) )

To apply this formula to your problem: (assuming that the dates are in row 1 and the values are in row 2) 将此公式应用于您的问题:(假设日期在第1行中,而值在第2行中)

  • insert a new row to hold the WEEKDAY() value (say, row 2) 插入新行以保存WEEKDAY()值(例如,第2行)
  • in cell A2 type in =WEEKDAY(A1) 在单元格A2中键入=WEEKDAY(A1)
  • copy this formula as far right as necessary (to include all your dates) 尽可能复制此公式(以包括所有日期)

Your average for Mondays is calculated as =AVERAGEIF(2:2, 2, 3:3) 您星期一的平均值计算为=AVERAGEIF(2:2, 2, 3:3)

If your date is in A1, you can use =Text(A1,"dddd") to determine the day of the week (it will return the name, "Monday", "Tuesday", etc.) so then you could do perhaps: 如果您的日期在A1中,则可以使用=Text(A1,"dddd")来确定星期几(它将返回名称“ Monday”,“ Tuesday”等),因此您可以执行:

=If(text(A1,"dddd")="Monday",[do whatever],[do whatever]) (may need a helper row/column to hold the text of the weekday) =If(text(A1,"dddd")="Monday",[do whatever],[do whatever]) (可能需要一个帮助行/列来保存工作日的文本)

(Or use AverageIf() and use the Text() idea.) (或者使用AverageIf()并使用Text()想法。)

Possibly, you can add a column called [Day Of The Week] and use the following formula to display the day. 可能可以添加名为[星期几]的列,并使用以下公式显示日期。

TEXT(B4,"dddd") TEXT(B4,“ dddd”)

Then add an 'If'statement to your result cell. 然后在结果单元格中添加一个“如果”语句。

simply 只是

=SUMPRODUCT((MOD(B1:V1,7)=2)*B20:V20)/SUMPRODUCT((MOD(B1:V1,7)=2)*1)

should give the average of all values from B20 to V20 if the corresponding cell in row 1 is a monday. 如果第1行中的相应单元格是星期一,则应给出从B20到V20的所有值的平均值。

the first part sums the values of all mondays and the second part counts them (sum / count = average) ;) 第一部分对所有星期一的值求和,第二部分对它们进行计数(总和/计数=平均值);)

If you have any questions, just ask. 如果你有问题,就问吧。

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

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