

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# percentDifference
<a name="percentDifference-function"></a>

`percentDifference` 函數會根據分割、排序和查詢索引計算目前值和比較值之間的百分比差異。

## 語法
<a name="percentDifference-function-syntax"></a>

需使用括弧。若要了解哪些參數是選用的，請參閱以下描述。

```
percentDifference
(
  measure 
  ,[ sortorder_field ASC_or_DESC, ... ]  
  ,lookup index
  ,[ partition_field, ... ] 
)
```

## 引數
<a name="percentDifference-function-arguments"></a>

 *measure*   
您要查看百分比差異之彙總的度量。

 *sort order field*   
您要排序資料依據的一或多個度量和維度，以逗號分隔。您可以指定遞增 (**ASC**) 或遞減 (**DESC**) 排序順序。  
如果有不只一個字，則清單中的每個欄位會括在 \$1\$1 (大括號) 中。整個清單會以 [ ] (方括弧) 括住。

 *lookup index*   
查詢索引可為正值或負值，代表排序中的下一個資料列 (正值) 或排序中的上一個資料列 (負值)。查詢索引可以是 1–2,147,483,647。對於 MySQL、MariaDB 和 Aurora MySQL 相容版引擎，查詢索引僅限為 1。

 *partition field*   
(選用) 您要分割依據的一或多個維度，以逗號分隔。  
如果有不只一個字，則清單中的每個欄位會括在 \$1\$1 (大括號) 中。整個清單會以 [ ] (方括弧) 括住。

## 範例
<a name="percentDifference-function-example"></a>

以下範例會計算目前和之前的 `State` 的 `sum(Sales)` 之間的百分比差異，依 `Sales` 排序。

```
percentDifference
(
  sum(amount), 
  [sum(amount) ASC],
  -1, 
  [State]
)
```

以下範例會計算特定 `Billed Amount` 屬於另一個 `Billed Amount` 的百分比，依據 (`[{Customer Region} ASC]`) 排序。資料表計算中的欄位位於視覺化效果的欄位區。

```
percentDifference
(
  sum( {Billed Amount} ), 
  [{Customer Region} ASC],
  1
)
```

以下螢幕擷取畫面顯示範例的結果。紅色字母顯示 `Customer Region` **APAC** 的 `Billed Amount` 總計較 **EMEA** 區域的金額少 24%。

![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/quick/latest/userguide/images/percentDifference.png)
