Skip to content

Commit 4b46c9c

Browse files
committed
docs: count_measure in the views reference
1 parent 5fd13d1 commit 4b46c9c

File tree

1 file changed

+67
-2
lines changed

1 file changed

+67
-2
lines changed

docs/pages/reference/data-model/view.mdx

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ view(`orders`, {
114114
},
115115
{
116116
join_path: base_orders.users,
117-
prefix: true
117+
prefix: true,
118118
includes: `*`,
119119
excludes: [
120120
`company`
@@ -254,6 +254,69 @@ To learn more about using `public` to control visibility based on security
254254
context, read the [Controlling access to cubes and views
255255
recipe][ref-recipe-control-access-cubes-views].
256256

257+
### `count_measure`
258+
259+
The `count_measure` parameter is used to explicitly specify the measure that
260+
should be used to generate the SQL for `SELECT COUNT(*) FROM view` queries via
261+
the [SQL API][ref-sql-api].
262+
263+
The specified measure should be of one of the following [types][ref-ref-measure-type-count]:
264+
`count`, `count_distinct`, or `count_distinct_approx`. It should also be included
265+
into the view in [`cubes`](#cubes).
266+
267+
<CodeTabs>
268+
269+
```javascript
270+
view(`orders`, {
271+
cubes: [
272+
{
273+
join_path: base_orders,
274+
includes: [
275+
`status`,
276+
`created_date`,
277+
`total_amount`,
278+
`total_amount_shipped`,
279+
`count`,
280+
`average_order_value`
281+
]
282+
},
283+
{
284+
join_path: base_orders.users,
285+
prefix: true,
286+
includes: `*`
287+
}
288+
],
289+
290+
count_measure: base_orders.count
291+
});
292+
```
293+
294+
```yaml
295+
views:
296+
- name: orders
297+
298+
cubes:
299+
- join_path: base_orders
300+
includes:
301+
- status
302+
- created_date
303+
- total_amount
304+
- total_amount_shipped
305+
- count
306+
- average_order_value
307+
308+
- join_path: base_orders.users
309+
prefix: true
310+
includes: "*"
311+
312+
count_measure: base_orders.count
313+
```
314+
315+
</CodeTabs>
316+
317+
If this parameter is not set, then the very first measure of [type `count`][ref-ref-measure-type-count]
318+
from the very first cube defined in [`cubes`](#cubes) will be used.
319+
257320
### `includes` (deprecated)
258321

259322
<WarningBox>
@@ -312,4 +375,6 @@ view query.
312375
/product/data-modeling/concepts/working-with-joins#directions-of-joins
313376
[ref-naming]: /product/data-modeling/syntax#naming
314377
[ref-playground]: /product/workspace/playground
315-
[ref-apis]: /product/apis-integrations
378+
[ref-apis]: /product/apis-integrations
379+
[ref-sql-api]: /product/apis-integrations/sql-api
380+
[ref-ref-measure-type-count]: /reference/data-model/types-and-formats#count

0 commit comments

Comments
 (0)