> For the complete documentation index, see [llms.txt](https://docs.coreway.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coreway.com/yoov-plus/worksheet/worksheet-design/field-type/formula-summary.md).

# 公式与汇总

这两个字段都是系统自动计算字段，用于对数据进行加工、统计，并输出计算结果。用户无法直接编辑它们的值。

## **1. 公式字段** <a href="#id-1-formula-field" id="id-1-formula-field"></a>

公式字段用于在本表内，根据其他字段值自动执行计算。分为**数字模式**和**日期模式**。

#### **1.1 数字模式** <a href="#id-1-1-number-mode" id="id-1-1-number-mode"></a>

* **计算方式**：
  * **预置运算**：直接选择求和、平均值、最大值、最小值、乘积等，并指定参与计算的字段。
  * **自定义公式**：支持使用 `+`, `-`, `*`, `/`, `()` 及内置函数编写复杂公式。
  * **空值处理**：可设置当参与计算的字段为空时，将其视为 `0` 或导致整个公式不计算。
* **结果显示设置**（与数字字段相同）：
  * **小数位**：设置保留位数，计算结果会**四舍五入**。
  * **千分位/百分比显示**：可选择以千分位分隔或百分比形式显示（注意：百分比显示仅改变外观，计算时仍使用原始值）。
  * **单位**：可添加前后缀单位。

<figure><img src="/files/m0VTYmHLKxRE0NuoEMgz" alt=""><figcaption></figcaption></figure>

#### **1.2 日期模式** <a href="#id-1-2-date-mode" id="id-1-2-date-mode"></a>

* **计算两日期间的时长**：
  * 需要指定开始和结束日期（可为字段或固定值）。
  * **格式化处理**：对不带时间的纯日期字段，可统一按“00:00”或“24:00”处理，确保计算准确。
  * **输出单位**：结果可按秒、分钟、小时、日、月、年输出，并可设置小数位。
* **为日期加减时长**：
  * 对一个日期进行增加或减少指定时长（如 `+8h-1d`）。
* **距离此刻的时长**：
  * 计算目标日期与当前时间的间隔，可设置不显示负数。

<figure><img src="/files/apNR0QHALepi2L24FczS" alt=""><figcaption></figcaption></figure>

## **2. 汇总字段** <a href="#id-2-summary-field" id="id-2-summary-field"></a>

汇总字段专用于对**关联记录（多条）** 或**子表**中的数据进行聚合统计。

#### **2.1 核心功能** <a href="#id-2-1-core-feature" id="id-2-1-core-feature"></a>

* **统计对象**：关联的多条记录，或子表内的所有行。
* **计算方式**：
  * 统计记录**数量**。
  * 对数字字段进行**求和、平均值、最大值、最小值**。
  * 对日期字段找出**最早、最晚**时间。
  * 统计字段的**已填/未填计数**。

#### **2.2 汇总范围（筛选统计）** <a href="#id-2-2-summary-scope-filter-stats" id="id-2-2-summary-scope-filter-stats"></a>

可设置筛选条件，**仅对符合条件**的关联记录或子表行进行统计。结果可以数值或**百分比**（符合条件的数量/总数量）形式显示。

#### **2.3 结果显示设置**（与公式字段相同）： <a href="#id-2-3-result-display-setting-same-as-formula-field" id="id-2-3-result-display-setting-same-as-formula-field"></a>

* **小数位**：设置保留位数，结果**四舍五入**。
* **千分位/百分比显示**：可选择以千分位分隔或百分比形式显示（此为数值的单位转换，与“汇总范围”的占比百分比不同）。
* **单位**：可添加前后缀单位。

<figure><img src="/files/3d4uyswdgQX4wIXRxei5" alt=""><figcaption></figcaption></figure>

***

## **3. 核心区别与选择** <a href="#id-3-core-difference-and-selection" id="id-3-core-difference-and-selection"></a>

| 特性        | 公式字段             | 汇总字段                      |
| --------- | ---------------- | ------------------------- |
| **计算数据源** | **本表**内的其他字段。    | **关联记录（多条）** 或 **子表**。    |
| **主要用途**  | 本表记录内部的数值、日期计算。  | 对“一对多”关系中的“多”方数据进行聚合统计。   |
| **典型场景**  | 计算金额小计、到期日期、工龄等。 | 统计客户订单总金额、项目任务平均进度、子表行数等。 |

<br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.coreway.com/yoov-plus/worksheet/worksheet-design/field-type/formula-summary.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
