查找在excel中花费时间最多的一天

j8ag8udp  于 2022-11-26  发布在  其他
关注(0)|答案(2)|浏览(141)

我有一个类似这样的电子表格,

Sunday,      Monday,      Tuesday,     Wednesday,   Thursday, Friday, Saturday, Sunday, Monday, Tuesday, ...
13-Nov-2022, 14-Nov-2022, 15-Nov-2022, 16-Nov-2022, 17-Nov-2022, ...
1:00,        2:05,        0:30,        2:00,        1:00,     0:05,   0:10,     1:20, 0:14

我想找出最大和的那一天,就是这里,星期日是2:20,所以我想在一个专栏里提到星期日。目前,我做了这样的事情,

MAX(SUMIFS(range_of_time_spent, range_of_days, a_particular_day), 
    SUMIFS(range_of_time_spent, range_of_days, a_particular_day),
    ...) # seven SUMIFS inside MAX for 7 different days

但这是2点20不是那天

ou6hu8tu

ou6hu8tu1#

用途:

=TEXT(INDEX({1,2,3,4,5,6,7},MATCH(MAX(SUMIFS(range_of_time_spent,range_of_days,TEXT({1,2,3,4,5,6,7},"dddd"))),SUMIFS(range_of_time_spent,range_of_days,TEXT({1,2,3,4,5,6,7},"dddd")),0)),"dddd")

对于旧版本,退出编辑模式时可能需要使用Ctrl-Shift-Enter而不是Enter。

jyztefdp

jyztefdp2#

You can try this approach that uses MMULT . In cell A6 put the following formula:

=INDEX(TEXT(SEQUENCE(7,1), "dddd"),
  MATCH(MAX(MMULT(IF(A1:O1=TEXT(SEQUENCE(7,1), "dddd"), A3:O3,0),
    TRANSPOSE(COLUMN(A1:O1)/COLUMN(A1:O1)))),
    MMULT(IF(A1:O1=TEXT(SEQUENCE(7,1), "dddd"), A3:O3,0),
      TRANSPOSE(COLUMN(A1:O1)/COLUMN(A1:O1))),0))

Notes:

  • MMULT requires as input arguments arrays, it means you can use either ranges or arrays, so it gives more flexibility in case you are forced to use arrays. Let's say instead of calculating the totals of A3:O3 , you need to perform an operation first in the range, for example: LOG10(A3:O3) (now it is not a range but an array) or any other operation. In this case you cannot use any of the RACON excel functions , because they work only with ranges.
  • I borrow the idea from @ScottCraner's answer to generate the week days via TEXT function. Great trick 1 represents the day: 1/1/1900 that was a Sunday and so on until: 7 , i.e. 1/7/1900 that was a Saturday.

and here is the output:

Since you requested a solution for an older version, the above formula is more verbose. Let's use LET function ( Excel 2021 version ) to avoid repetition of the same calculation defining names. It also facilitates the comprehension of the formula (You can use named ranges for some of the range too)

=LET(wkdays, TEXT(SEQUENCE(7,1), "dddd"), days, A1:O1, times, A3:O3,
 matrix, IF(days=wkdays, times,0),cols, COLUMN(days), 
 ones, TRANSPOSE(cols/cols),
 totals, MMULT(matrix, ones),
 INDEX(wkdays, XMATCH(MAX(totals), totals))
)

The main idea is to generate the matrix so we can perform the calculation in the way we want it. Let's try to understand the following expression first:

IF(a = b, c, 0)

If a is an 1xm array and b an nx1 and c has the same shape as a . It returns an nxm array, where on each row is compared the corresponding element of b against the entire array a . if there is a match it returns the corresponding value of c , otherwise returns 0 . Here is the mathematical representation for the elements of the resulting matrix:

For example:

IF({1,2,3,1,2,3}={1;2;3},{10,20,30,40,50,60},0)

returns

10  0   0   10  0   0
0   20  0   0   20  0
0   0   30  0   0   30

If we do a matrix multiplication of the previous result: MMULT(matrix, {1;1;1;1;1;1}) we obtain the totals per row and this is exactly what we want.
Understanding the previous logic. We just need to build the same logic adapted to our specific data:

  • wkdays has the weekdays in a row array (array b from previous example)
  • days the list of days (only weekday portion) in a column array (array a )
  • ones is the unit row array with the same number of rows as columns has days .
  • times The times, the information we want to calculate the totals (array c )
  • matrix generates a matrix using the logic explained before, but applied to our case: IF(days=wkdays, times,0)
  • totals is the matrix multiplication: MMULT(matrix, ones) returns the total of times per wkdays .

The rest is just to find the index position of the maximum of totals via MATCH/XMATCH and finally use INDEX to find the corresponding weekday.

相关问题