# 報表產生器函式 - 彙總函式參考Report Builder Functions - Aggregate Functions Reference

## 內建彙總函式Built-in Aggregate Functions

AvgAvg 傳回運算式指定的所有非 Null 數值的平均值 (在給定範圍中評估)。Returns the average of all non-null numeric values specified by the expression, evaluated in the given scope.

CountDistinctCountDistinct 傳回運算式指定的所有非 Null 相異值的計數 (在給定範圍的內容中評估)。Returns a count of all distinct non-null values specified by the expression, evaluated in the context of the given scope.
MaxMax 傳回運算式指定的所有非 Null 數值的最大值 (在給定範圍的內容中)。Returns the maximum value of all non-null numeric values specified by the expression, in the context of the given scope. 這個函數可用來指定圖表軸的最大值以控制刻度。You can use this for specifying a chart axis maximum value to control the scale.
MinMin 傳回運算式指定的所有非 Null 數值的最小值 (在給定範圍的內容中)。Returns the minimum value of all non-null numeric values specified by the expression, in the context of the given scope. 這個函數可用來指定圖表軸的最小值以控制刻度。You can use this for specifying a chart axis minimum value to control the scale.
StDevStDev 傳回運算式指定的所有非 Null 數值的標準差 (在給定範圍中評估)。Returns the standard deviation of all non-null numeric values specified by the expression, evaluated in the given scope.
StDevPStDevP 傳回運算式指定的所有非 Null 數值的母體標準差 (在給定範圍的內容中評估)。Returns the population standard deviation of all non-null numeric values specified by the expression, evaluated in the context of the given scope.
SumSum 傳回運算式指定之所有非 Null 數值的總和 (在給定範圍中評估)。Returns the sum of all the non-null numeric values specified by the expression, evaluated in the given scope.
UnionUnion 傳回運算式所指定之 SqlGeometrySqlGeography 類型的所有非 Null 空間資料值聯集 (在給定的範圍中評估)。Returns the union of all the non-null spatial data values of type SqlGeometry or SqlGeography that are specified by the expression, evaluated in the given scope.
VarVar 傳回運算式指定的所有非 Null 數值的變異數 (在給定範圍中評估)。Returns the variance of all non-null numeric values specified by the expression, evaluated in the given scope.
VarPVarP 傳回運算式指定的所有非 Null 數值的母體擴展變異數 (在給定範圍的內容中評估)。Returns the population variance of all non-null numeric values specified by the expression, evaluated in the context of the given scope.

## 內建欄位、集合和彙總函式的限制Restrictions on Built-in Fields, Collections, and Aggregate Functions

TotalPagesTotalPages
DataSourceDataSource

DataSetDataSet

Yes Yes 最多一個At most one

Yes Yes Yes Yes

Yes 只有目前範圍或包含範圍內的項目Only items in the currnet scope or a containing scope

No Yes Yes Yes

No No No No No

No

No

No No No No No

• 附註 1：Note 1. ReportItems 必須存在於轉譯的報表頁面中，否則其值會是 Null。ReportItems must exist in the rendered report page, or their value is Null. 如果報表項目的可見性取決於評估為 False 的運算式，則表示報表項目不存在於頁面上。If the visibility of a report item depends on an expression that evaluates to False, the report item does not exist on the page.

• 附註 2。Note 2. 如果欄位參考用於群組範圍中，而且欄位參考未包含在群組運算式中，則表示未定義該欄位的值，除非此範圍內只有一個值。If a field reference is used in a group scope, and the field reference is not included in the group expression, then the value for the field is undefined, unless there is only one value in the scope. 若要指定值，請使用 First 或 Last 及群組範圍。To specify a value, use First or Last and the group scope.

• 附註 3。Note 3. 包含 ReportItems 之參考的運算式可以針對相同群組範圍或包含的群組範圍內的其他 ReportItems 指定值。Expressions that include a reference to ReportItems can specify values for other ReportItems in the same group scope or in a containing group scope.

• 附註 4。Note 4. 之前參數的屬性值可能為 null。Property values for earlier parameters might be null.

• 附註 5。Note 5. 僅限成員排序。In Member sorts only. 無法在資料區排序運算式內使用。Cannot use in data region sort expressions.

• 附註 6。Note 6. 僅限成員篩選。In Member filters only. 無法在資料區或資料集篩選運算式內使用。Cannot use in data region or dataset filter expressions.

• 附註 7。Note 7. 處理程式碼區塊之前沒有初始化參數集合，所以無法使用方法來控制初始化的參數。The Parameters collection is not initialized until after the Code block is processed, so methods cannot be used to control parameters on initialization.

• 附註 8。Note 8. 除了 Count 與 CountDistinct 以外的所有彙總之資料類型，所有的值都必須是相同的資料類型或 null。Data type for all aggregates except Count and CountDistinct must be the same data type, or null, for all values.

回到頁首Back to Top

## 巢狀彙總的限制Restrictions on Nested Aggregates

PreviousPrevious Sum 和其他 Presort 函數Sum and Other Presort functions ReportItem 彙總ReportItem aggregates 查閱函數Lookup functions 彙總函式Aggregate Function

No No No No Yes No No No
PreviousPrevious Yes Yes Yes No Yes No Yes No
Sum 和其他 Presort 函數Sum and other Presort functions No No No No Yes No Yes No
ReportItem 彙總ReportItem aggregates No No No No No No No No

Yes

Yes

Yes

Yes

No No

• 附註 1：Note 1. 如果查閱函數未包含在彙總內，則只有查閱函數的 Source 運算式中才允許彙總函式。Aggregate functions are only allowed inside the Source expression of a Lookup function if the Lookup function is not contained in an aggregate. 查閱函數的 DestinationResult 運算式內不允許彙總函式。Aggregate functions are not allowed inside the Destination or Result expressions of a Lookup function.

回到頁首Back to Top

## 計算執行值Calculating Running Values

RowNumberRowNumber 傳回指定範圍中資料列數的執行計數。Returns a running count of the number of rows for the specified scope. RowNumber 函數從 1 開始重新計數，而不是 0。The RowNumber function restarts counting at 1, not 0.
RunningValueRunningValue 傳回運算式指定的所有非 Null 數值的執行彙總 (在給定範圍中評估)。Returns a running aggregate of all non-null numeric values specified by the expression, evaluated for the given scope.

## 擷取資料列計數Retrieving Row Counts

CountRowsCountRows 傳回指定之範圍中的資料列數目，包括具有 Null 值的資料列。Returns the number of rows in the specified scope, including rows with null values.

## 從其他資料集查詢值Looking Up Values from Another Dataset

Lookup 函數Lookup Function 從指定之運算式的資料集傳回值。Returns a value from a dataset for a specified expression.
LookupSet 函數LookupSet Function 從指定之運算式的資料集傳回一組值。Returns a set of values from a dataset for a specified expression.
Multilookup 函數Multilookup Function 從包含名稱/值組的資料集傳回第一組符合某一組名稱的值。Returns the set of first-match values for a set of names from a dataset that contains name/value pairs.

## 擷取與排序相依的值Retrieving Sort-Dependent Values

PreviousPrevious 傳回某個項目在指定之範圍內上一個執行個體的值或指定的彙總值。Returns the value or the specified aggregate value for the previous instance of an item within the specified scope.

## 擷取伺服器彙總Retrieving Server Aggregates

AggregateAggregate 傳回指定之運算式的自訂彙總，由資料提供者定義。Returns a custom aggregate of the specified expression, as defined by the data provider.

## 測試範圍Testing for Scope

InScopeInScope 指出目前項目的執行個體是否在指定的範圍內。Indicates whether the current instance of an item is within the specified scope.

## 擷取遞迴層級Retrieving Recursive Level

LevelLevel 傳回遞迴階層中之目前所在的層級。Returns the current level of depth in a recursive hierarchy.