You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Google Sheets条件求和/按周平均工时动态公式需求

Google Sheets Solution for Weekly Work Hour Calculation

Step 1: Clean Raw Data (Handle Duplicate Body Parts)

First, we'll preprocess the raw data to average hours for any duplicate body parts. Assuming your raw data is in Sheet1!A1:F, add this formula to a blank range in Sheet1 (e.g., H1) to create a cleaned dataset:

=QUERY(A1:F, "SELECT A, B, C, AVG(D), AVG(E), AVG(F) GROUP BY A, B, C", 1)

This groups rows by body part, start week, and end week, then averages the hours for each person. If there are no duplicates, it just returns the original data—safe to use either way.

Cleaned data columns will be:

  • H: Body Part
  • I: Start Week
  • J: End Week
  • K: Arnold (avg hours)
  • L: Usian (avg hours)
  • M: Bob (avg hours)

Step 2: Set Up the Target Report

In a new sheet (e.g., Sheet2):

  • A1: 工时
  • B1: Arnold
  • C1: Usian
  • D1: Bob
  • F1: Start Week (input your desired start week here, e.g., 1)
  • G1: End Week (input your desired end week here, e.g., 6)

Generate dynamic week labels in A2:A with:

=ARRAYFORMULA("Week "&SEQUENCE(G1-F1+1,1,F1))

This updates automatically if you change the start/end week values in F1/G1.

Step 3: Core Weekly Calculation Formulas

Use these formulas to calculate the weekly hours for each person. They’ll adjust automatically when start/end weeks change.

Arnold’s Column (B2)

=BYROW(A2:A, LAMBDA(week, IF(week="", "", SUMPRODUCT((Sheet1!$I$2:$I <= VALUE(RIGHT(week,2))) * (VALUE(RIGHT(week,2)) <= Sheet1!$J$2:$J) * (Sheet1!$K$2:$K/(Sheet1!$J$2:$J - Sheet1!$I$2:$I +1))))))

Usian’s Column (C2)

=BYROW(A2:A, LAMBDA(week, IF(week="", "", SUMPRODUCT((Sheet1!$I$2:$I <= VALUE(RIGHT(week,2))) * (VALUE(RIGHT(week,2)) <= Sheet1!$J$2:$J) * (Sheet1!$L$2:$L/(Sheet1!$J$2:$J - Sheet1!$I$2:$I +1))))))

Bob’s Column (D2)

=BYROW(A2:A, LAMBDA(week, IF(week="", "", SUMPRODUCT((Sheet1!$I$2:$I <= VALUE(RIGHT(week,2))) * (VALUE(RIGHT(week,2)) <= Sheet1!$J$2:$J) * (Sheet1!$M$2:$M/(Sheet1!$J$2:$J - Sheet1!$I$2:$I +1))))))

How It Works

  • BYROW iterates over each week label in A2:A
  • VALUE(RIGHT(week,2)) extracts the numeric week number from "Week X"
  • The boolean checks (<=, >=) filter rows where the week falls within the activity’s start/end range
  • Sheet1!$K$2:$K/(Sheet1!$J$2:$J - Sheet1!$I$2:$I +1) calculates the weekly contribution for each activity (total hours divided by the number of weeks it spans)
  • SUMPRODUCT sums all valid weekly contributions for the week

Step 4: Format for Target Output

Select columns B:D, go to Format > Number > Number and set decimal places to 2 to match the target report’s formatting.

Verification

For example, Week 1 Arnold’s total:

  • Arms: 6 hours / 3 weeks = 2
  • Legs:12 hours /6 weeks=2
  • Core:10 hours/5 weeks=2
    Sum: 2+2+2=6, which matches the target value.

内容的提问来源于stack exchange,提问作者Logan Schenkey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.10 18:25:34