# 聚合计算函数

在创建指标（Measure）时，聚合函数是对数据进行汇总和计算的基础工具。\
这些函数用于一组数值，并返回一个汇总结果，帮助提炼和呈现关键信息。

## 支持的聚合函数

Recurve 支持以下聚合函数：

### **1. SUM（求和）**

计算数值字段的总和。

**示例**：`SUM(revenue)`

返回所有记录的 **总收入**。

### **2. COUNT（计数）**

计算记录的总数。

**示例**：`COUNT(order_id)`

返回 **订单总数**。

### **3. COUNT DISTINCT（去重计数）**

计算字段中唯一值的个数。

**示例**：`COUNT_DISTINCT(customer_id)`

返回 **唯一客户数**。

### **4. AVG（平均值）**

计算数值字段的平均值。

**示例**：`AVG(order_amount)`

返回 **平均订单金额**。

### **5. MIN（最小值）**

查找字段中的最小值。

**示例**：`MIN(price)`

返回 **最低产品价格**。

### **6. MAX（最大值）**

查找字段中的最大值。

**示例**：`MAX(price)`

返回 **最高产品价格**。

### **7. CUSTOM（自定义）**

允许用户通过公式自定义聚合逻辑。

**示例**：`SUM(revenue) / COUNT(order_id)`

计算 **每单平均收入**。

## 在指标中的使用

定义指标时，必须指定聚合函数，以确定数据的汇总方式。以下是聚合函数在指标定义中的使用示例：

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

```yaml
measures:
  - name: sum_order_total
    label: "总收入"
    type: decimal
    aggregation: SUM
    expression: "SUM(order_total)" -- order_total 为语义模型中已有的字段名称
```

该指标通过汇总 `order_total` 字段，计算 **总收入**。


---

# Agent Instructions: 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:

```
GET https://docs.reorc.com/cn-reorc-help-center/semantics_modeling/yu-yi-ceng-mo-xing-cube/zi-ding-yi-zhi-biao/ju-he-ji-suan-han-shu.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
