@@ -14,6 +14,105 @@ redirect_from:
1414This section describes the various types that can be assigned to a ** measure** .
1515A measure can only have one type.
1616
17+ ### <--{"id" : " Measure Types" }--> string
18+
19+ This measure type allows defining measures as a ` string ` value. In the example below,
20+ we create a ` string ` measure by converting a numerical value to a string:
21+
22+ <CodeTabs >
23+
24+ ``` javascript
25+ cube (' Orders' , {
26+ measures: {
27+ high_or_low: {
28+ type: ` string` ,
29+ sql: ` CASE WHEN ${ CUBE .number } > 100 THEN 'high' ELSE 'low' END` ,
30+ },
31+ },
32+ });
33+ ```
34+
35+ ``` yaml
36+ cubes :
37+ - name : Orders
38+ measures :
39+ - name : high_or_low
40+ sql : " CASE WHEN {CUBE.number} > 100 THEN 'high' ELSE 'low' END"
41+ type : string
42+ ` ` `
43+
44+ </CodeTabs>
45+
46+ ### <--{"id" : "Measure Types"}--> time
47+
48+ This measure type allows defining measures as a ` time` value. In the example below,
49+ we create a `time` measure from an existing dimension :
50+
51+ <CodeTabs>
52+
53+ ` ` ` javascript
54+ cube('Orders', {
55+ measures: {
56+ last_order: {
57+ sql: ` MAX(created_at)`,
58+ type : ` time` ,
59+ },
60+ },
61+ dimensions : {
62+ created_at : {
63+ sql : ` created_at` ,
64+ type : ` time` ,
65+ },
66+ },
67+ });
68+ ```
69+
70+ ``` yaml
71+ cubes :
72+ - name : Orders
73+ measures :
74+ - name : last_order
75+ sql : " MAX(created_at)"
76+ type : time
77+ dimensions :
78+ - name : created_at
79+ sql : created_at
80+ type : time
81+ ` ` `
82+
83+ </CodeTabs>
84+
85+ ### <--{"id" : "Measure Types"}--> boolean
86+
87+ The ` boolean` measure type can be used to condense data into a single boolean value.
88+
89+ The example below adds an `is_completed` measure which only returns `true` if
90+ **all** orders have the `completed` status:
91+
92+ <CodeTabs>
93+
94+ ` ` ` javascript
95+ cube('Orders', {
96+ measures: {
97+ is_completed: {
98+ sql: ` BOOL_AND(status = 'completed')`,
99+ type : ` boolean` ,
100+ },
101+ },
102+ });
103+ ```
104+
105+ ``` yaml
106+ cubes :
107+ - name : Orders
108+ measures :
109+ - name : is_completed
110+ sql : " BOOL_AND(status = 'completed')"
111+ type : boolean
112+ ` ` `
113+
114+ </CodeTabs>
115+
17116### <--{"id" : "Measure Types"}--> number
18117
19118The ` sql` parameter is required and can take any valid SQL expression that
@@ -40,7 +139,7 @@ cubes:
40139 - name : Orders
41140 measures :
42141 - name : purchases_ratio
43- sql : $ {purchases} / $ {count} * 100.0
142+ sql : " {purchases} / {count} * 100.0"
44143 type : number
45144 format : percent
46145` ` `
@@ -68,7 +167,7 @@ cubes:
68167 - name : Orders
69168 measures :
70169 - name : ratio
71- sql : ' SUM({CUBE}.amount) / count(*)'
170+ sql : " SUM({CUBE}.amount) / count(*)"
72171 type : number
73172` ` `
74173
@@ -791,7 +890,6 @@ cubes:
791890
792891[ref-string-time-dims]:
793892 /schema/fundamentals/additional-concepts#string-time-dimensions
794- [ref-schema-ref-preaggs-rollup]:
795- /schema/reference/pre-aggregations#type-rollup
893+ [ref-schema-ref-preaggs-rollup]: /schema/reference/pre-aggregations#type-rollup
796894[ref-schema-ref-calc-measures]: /schema/reference/measures#calculated-measures
797895[ref-drilldowns]: /schema/fundamentals/additional-concepts#drilldowns
0 commit comments