# NoOfRows 指令碼與圖表函數

NoOfRows() 傳回表格中目前資料行區段中的列數。對於點陣圖圖表，NoOfRows() 傳回圖表的連續表同等表格中的列數。

如果表格或同等表格有多個垂直維度，則目前資料行區段僅會包含在所有維度資料行中與目前列有相同值的列，除了顯示在欄位間排序順序中為最後一個維度的資料行之外。

資訊備註當任何圖表運算式使用了此圖表函數時，就不允許在圖表中依據 Y 值排序，或在表格中依據運算式資料行排序。因此，這些排序替代選項會自動停用。若您在視覺化或表格中使用此圖表函數，視覺化的排序將還原為對此函數的排序輸入。

語法：

NoOfRows([TOTAL])

傳回的資料類型： 整數

引數：

引數

| 引數 | 描述 |
| --- | --- |
| TOTAL | 如果表格為單一維度或 TOTAL 限定詞作為引數，則目前資料行區段一律等於整個資料行。<br><br>[定義彙總範圍](https://help.qlik.com/zh-TW/cloud-services/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/define-aggregation-scope.htm) |

## 範例：使用 NoOfRows 的圖表運算式

[](https://help.qlik.com/en-US/cloud-services/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/InterRecordFunctions/noofrows.htm)

#### 範例 - 圖表運算式

### 載入指令碼

在資料載入編輯器中載入下列資料作為內嵌載入，以建立以下的圖表運算式範例。

```
	Temp:
LOAD * inline [
Region|SubRegion|RowNo()|NoOfRows()
Africa|Eastern
Africa|Western
Americas|Central
Americas|Northern
Asia|Eastern
Europe|Eastern
Europe|Northern
Europe|Western
Oceania|Australia
] (delimiter is '|');
```

如需更多關於使用內嵌載入的資訊，請參閱 [使用內嵌載入以載入資料](https://help.qlik.com/zh-TW/cloud-services/Subsystems/Hub/Content/Sense_Hub/Scripting/inline-loads-qs.htm)。

### 圖表運算式

在 Qlik Sense 工作表中建立具有 Region 和 SubRegion 作為維度的表格視覺化。將 `RowNo( )`、`  NoOfRows() ` 和 `  NoOfRows(Total) ` 新增為量值。

### 結果

| Region | SubRegion | RowNo() | NoOfRows() | NoOfRows(Total) |
| --- | --- | --- | --- | --- |
| Africa | Eastern | 1 | 2 | 9 |
| Africa | Western | 2 | 2 | 9 |
| Americas | Central | 1 | 2 | 9 |
| Americas | Northern | 2 | 2 | 9 |
| Asia | Eastern | 1 | 1 | 9 |
| Europe | Eastern | 1 | 3 | 9 |
| Europe | Northern | 2 | 3 | 9 |
| Eurrope | Western | 3 | 3 | 9 |
| Oceania | Australia | 1 | 1 | 9 |

### 解釋

在此範例中，排序順序依據第一個維度 Region。因此，每個資料行區段由具有相同值的區域群組組成，例如非洲。

RowNo() 資料行顯示每個資料行區段的列數，例如非洲區域有兩列。接著下一個資料行區段 Americas 的列編號會再度從 1 開始。

NoOfRows() 資料行計算每個資料行區段中的列數，例如歐洲在資料行區段中有三列。

由於 `NoOfRows()` 的 `TOTAL` 引數， NoOfRows(Total) 資料行會忽略維度，並計入表格中的列。

若表格排序在第二個維度 SubRegion，資料行區段會以該維度為基礎，因此每個 SubRegion 的列數計算會變更。

如需關於運算式的詳細資訊，請參閱[在視覺化中使用運算式](https://help.qlik.com/zh-TW/cloud-services/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/use-expressions-in-visualizations.htm)。

## 瞭解更多資訊

* [RowNo - 圖表函數](https://help.qlik.com/zh-TW/cloud-services/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/InterRecordFunctions/rowno.htm)