# autonumberhash256 指令碼函數

此指令碼函數會計算組合輸入運算式值的 256 位元雜湊，並針對在指令碼執行期間出現的每個相異的雜湊值，傳回唯一的整數值。此函數可用於如建立複雜金鑰的簡潔記憶表示法。

資訊備註您只能連接已在相同資料載入中產生的 autonumberhash256 索引鍵，因為根據表格的讀取順序產生了整數。如果您需要在資料載入之間使用持續存在的索引鍵，無論來源資料排序為何，您應該使用 hash128、hash160 或 hash256 函數。

語法：

autonumberhash256(expression {, expression})

範例： 建立複合索引鍵

在此範例中，我們使用 autonumberhash256 函數建立複合索引鍵以節省開支。該範例僅供示範之用，在處理含大量列的表格時具有意義。

範例表格

| Region | Year | Month | Sales |
| --- | --- | --- | --- |
| North | 2014 | May | 245 |
| North | 2014 | May | 347 |
| North | 2014 | June | 127 |
| South | 2014 | June | 645 |
| South | 2013 | May | 367 |
| South | 2013 | May | 221 |

使用內嵌資料載入來源資料。然後，我們新增一個前置載入，從 Region、Year 和 Month 欄位中建立複合索引鍵。

```
RegionSales:
LOAD *,
AutoNumberHash256(Region, Year, Month) as RYMkey;

LOAD * INLINE
[ Region, Year, Month, Sales
North,	2014,	May,	245
North,	2014,	May,	347
North,	2014,	June,	127
South,	2014,	June,	645
South,	2013,	May, 367
South,	2013,	May,	221
];
```

產生的表格如下所示：

結果表格

| Region | Year | Month | Sales | RYMkey |
| --- | --- | --- | --- | --- |
| North | 2014 | May | 245 | 1 |
| North | 2014 | May | 347 | 1 |
| North | 2014 | June | 127 | 2 |
| South | 2014 | June | 645 | 3 |
| South | 2013 | May | 367 | 4 |
| South | 2013 | May | 221 | 4 |

在此範例中，如果您需要連結至另一個表格，則可以參照 RYMkey (對於範例 1)，替代字串 'North2014May'。

現在，我們使用類似的方法載入成本來源表格。在前置載入中排除 Region、Year 和 Month 欄位，以避免建立合成鍵，我們已使用 autonumberhash256 函數建立複合索引鍵，進而連結表格。

```
RegionCosts:
LOAD Costs,
AutoNumberHash256(Region, Year, Month) as RYMkey;

LOAD * INLINE
[ Region, Year, Month, Costs
South,	2013,	May,	167
North,	2014,	May,	56
North,	2014,	June,	199
South,	2014,	June,	64
South,	2013,	May, 172
South,	2013,	May,	126
];
```

現在，我們可以將表格視覺化新增至工作表，並新增 Region、Year 和 Month 欄位，以及銷售額和成本的 Sum 量值。該表格將如下所示：

結果表格

| Region | Year | Month | Sum([Sales]) | Sum([Costs]) |
| --- | --- | --- | --- | --- |
| Totals | - | - | 1952 | 784 |
| North | 2014 | June | 127 | 199 |
| North | 2014 | May | 592 | 56 |
| South | 2014 | June | 645 | 64 |
| South | 2013 | May | 588 | 465 |

## 瞭解更多資訊

* [autonumberhash128 指令碼函數](https://help.qlik.com/zh-TW/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/CounterFunctions/autonumberhash128.htm)
* [autonumber 指令碼函數](https://help.qlik.com/zh-TW/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/CounterFunctions/autonumber.htm)