# 基本彙總函數

基本彙總函數是一組最常見的彙總函數。

使用每個函數中的下拉式功能表，以查看每個函數的簡要描述及語法。按一下語法描述中的函數名稱，以取得進一步詳細資料。

## 資料載入指令碼中的基本彙總函數

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/basic-aggregation-functions.htm)

#### FirstSortedValue

FirstSortedValue() 從運算式中傳回 value 中指定的值，該值對應於排序 sort\_weight 引數的結果，例如，具有最低單價之產品的名稱。可以在 rank 中指定排序順序中的第 n 個值。如果對於指定的 rank，有多個產生的值共用同一 sort\_weight，則該函數會傳回 NULL。 已排序的值會在許多記錄上反覆運算，如 group by 子句所定義，或者如果未定義任何 group by 子句則在整個資料集上彙總。

[**firstsorted**](https://help.qlik.com/zh-TW/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/firstsorted.htm)([**firstsorted**](https://help.qlik.com/zh-TW/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/firstsorted.htm)**firstsorted**firstsorted([ distinctdistinct ] expression, sort\_weight [, rank ] ] expression, sort\_weight [, rank ]))

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/basic-aggregation-functions.htm)

#### Max

Max() 會尋找運算式中已彙總資料的最高數值，如 group by 子句所定義。透過指定 rank n，可以找到第 n 個最高的值。

[**max**](https://help.qlik.com/zh-TW/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/max.htm)([**max**](https://help.qlik.com/zh-TW/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/max.htm)**max**max( expression[, rank] expression[, rank]))

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/basic-aggregation-functions.htm)

#### Min

Min() 會傳回運算式中已彙總資料的最低數值，如 group by 子句所定義。透過指定 rank n，可以找到第 n 個最低的值。

[**min**](https://help.qlik.com/zh-TW/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/min.htm)([**min**](https://help.qlik.com/zh-TW/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/min.htm)**min**min( expression[, rank] expression[, rank]))

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/basic-aggregation-functions.htm)

#### Mode

Mode() 會傳回運算式中已彙總資料的最常出現值 (模式值)，如 group by 子句所定義。Mode() 函數可傳回數值和文字值。

[**mode**](https://help.qlik.com/zh-TW/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/mode.htm)([**mode**](https://help.qlik.com/zh-TW/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/mode.htm)**mode**mode(expression expression ))

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/basic-aggregation-functions.htm)

#### Only

如果已彙總的資料中有一個可能的結果並且只有一個，則 Only() 會傳回一個值。如果記錄僅包含一個值，則傳回該值，否則傳回 NULL。使用 group by 子句，可在多筆記錄上評估。Only() 函數可傳回數值和文字值。

[**only**](https://help.qlik.com/zh-TW/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/only.htm)([**only**](https://help.qlik.com/zh-TW/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/only.htm)**only**only(expression expression ))

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/basic-aggregation-functions.htm)

#### Sum

Sum() 會計算運算式中已彙總值的總計，如 group by 子句所定義。

[**sum**](https://help.qlik.com/zh-TW/sense/May2026/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/sum.htm)([distinct]expression)

## 圖表運算式中的基本彙總函數

圖表彙總函數只能用於圖表運算式中的欄位。一個彙總函數的引數運算式不能包含另一個彙總函數。

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/basic-aggregation-functions.htm)

#### FirstSortedValue

FirstSortedValue() 從運算式中傳回 value 中指定的值，該值對應於排序 sort\_weight 引數的結果，例如，具有最低單價之產品的名稱。可以在 rank 中指定排序順序中的第 n 個值。如果對於指定的 rank，有多個產生的值共用同一 sort\_weight，則該函數會傳回 NULL。

[**firstsortedvalue**](https://help.qlik.com/zh-TW/sense/May2026/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/BasicAggregationFunctions/firstsortedvalue.htm)([{SetExpression}] [DISTINCT] [TOTAL [&lt;fld {,fld}&gt;]] value, sort\_weight [,rank])

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/basic-aggregation-functions.htm)

#### Max

Max() 會找到已彙總之資料中的最高值。透過指定 rank n，可以找到第 n 個最高的值。

[**max**](https://help.qlik.com/zh-TW/sense/May2026/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/BasicAggregationFunctions/max.htm)([{SetExpression}] [DISTINCT] [TOTAL [&lt;fld {,fld}&gt;]] expr [,rank])

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/basic-aggregation-functions.htm)

#### Min

Min() 會找到已彙總之資料中的最低值。透過指定 rank n，可以找到第 n 個最低的值。

[**min**](https://help.qlik.com/zh-TW/sense/May2026/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/BasicAggregationFunctions/min.htm)([{SetExpression}] [DISTINCT] [TOTAL [&lt;fld {,fld}&gt;]] expr [,rank])

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/basic-aggregation-functions.htm)

#### Mode

Mode() 會在已彙總之資料中找到最常發生的值，即模式值。Mode() 函數可以處理文字值以及數值。

[**mode**](https://help.qlik.com/zh-TW/sense/May2026/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/BasicAggregationFunctions/mode.htm) ({[SetExpression] [TOTAL [&lt;fld {,fld}&gt;]]} expr)

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/basic-aggregation-functions.htm)

#### Only

如果已彙總的資料中有一個可能的結果並且只有一個，則 Only() 會傳回一個值。例如，如果多個產品有單價 9，則僅搜尋單價 = 9 的產品將傳回 NULL。

[**only**](https://help.qlik.com/zh-TW/sense/May2026/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/BasicAggregationFunctions/only.htm)([{SetExpression}] [DISTINCT] [TOTAL [&lt;fld {,fld}&gt;]] expr)

[](https://help.qlik.com/en-US/sense/Subsystems/Hub/Content/Sense_Hub/Scripting/AggregationFunctions/basic-aggregation-functions.htm)

#### Sum

Sum() 會計算已彙總的資料中，運算式或欄位提供的值總計。

[**sum**](https://help.qlik.com/zh-TW/sense/May2026/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/BasicAggregationFunctions/sum.htm)([{SetExpression}] [DISTINCT] [TOTAL [&lt;fld {,fld}&gt;]] expr])