@sisense/sdk-data 0.15.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dimensional-model/analytics/factory.d.ts +47 -0
- package/dist/dimensional-model/analytics/factory.js +140 -0
- package/dist/dimensional-model/data-model.js +5 -4
- package/dist/dimensional-model/factory.js +2 -2
- package/dist/dimensional-model/filters/factory.d.ts +34 -1
- package/dist/dimensional-model/filters/factory.js +56 -0
- package/dist/dimensional-model/filters/filters.d.ts +4 -0
- package/dist/dimensional-model/filters/filters.js +10 -10
- package/dist/dimensional-model/interfaces.d.ts +15 -2
- package/dist/dimensional-model/measures/factory.d.ts +547 -177
- package/dist/dimensional-model/measures/factory.js +550 -189
- package/dist/dimensional-model/measures/measures.js +6 -6
- package/dist/index.d.ts +43 -36
- package/dist/index.js +43 -36
- package/dist/interfaces.d.ts +1 -1
- package/dist/translation/initialize-i18n.d.ts +2 -0
- package/dist/translation/initialize-i18n.js +10 -0
- package/dist/translation/resources/en.d.ts +28 -0
- package/dist/translation/resources/en.js +27 -0
- package/dist/translation/resources/index.d.ts +53 -0
- package/dist/translation/resources/index.js +7 -0
- package/dist/translation/resources/uk.d.ts +5 -0
- package/dist/translation/resources/uk.js +27 -0
- package/dist/translation/translatable-error.d.ts +5 -0
- package/dist/translation/translatable-error.js +11 -0
- package/dist/utils.d.ts +16 -0
- package/dist/utils.js +63 -0
- package/package.json +14 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DimensionalBaseMeasure, DimensionalCalculatedMeasure } from './measures.js';
|
|
2
2
|
import { AggregationTypes, MetadataTypes, Sort } from '../types.js';
|
|
3
3
|
import { normalizeName } from '../base.js';
|
|
4
|
-
import
|
|
4
|
+
import mapValues from 'lodash/mapValues.js';
|
|
5
5
|
import { DimensionalAttribute, DimensionalLevelAttribute } from '../attributes.js';
|
|
6
6
|
import { isDatetime, isNumber } from './../simple-column-types.js';
|
|
7
7
|
/**
|
|
@@ -11,19 +11,19 @@ import { isDatetime, isNumber } from './../simple-column-types.js';
|
|
|
11
11
|
*/
|
|
12
12
|
export const RankingTypes = {
|
|
13
13
|
/**
|
|
14
|
-
* In competition ranking, items that
|
|
14
|
+
* In competition ranking, items that rank equally receive the same ranking number, and then a gap is left after the equally ranked items in the ranking numbers.
|
|
15
15
|
*/
|
|
16
16
|
StandardCompetition: '1224',
|
|
17
17
|
/**
|
|
18
|
-
*
|
|
18
|
+
* In modified competition ranking, items that rank equally receive the same ranking number, and a gap is left before the equally ranked items in the ranking numbers.
|
|
19
19
|
*/
|
|
20
20
|
ModifiedCompetition: '1334',
|
|
21
21
|
/**
|
|
22
|
-
* In dense ranking, items that
|
|
22
|
+
* In dense ranking, items that rank equally receive the same ranking number, and the next items receive the immediately following ranking number.
|
|
23
23
|
*/
|
|
24
24
|
Dense: '1223',
|
|
25
25
|
/**
|
|
26
|
-
* In ordinal ranking, all items receive distinct ordinal numbers, including items that
|
|
26
|
+
* In ordinal ranking, all items receive distinct ordinal numbers, including items that rank equally. The assignment of distinct ordinal numbers for equal-ranking items is arbitrary.
|
|
27
27
|
*/
|
|
28
28
|
Ordinal: '1234',
|
|
29
29
|
};
|
|
@@ -98,63 +98,43 @@ function transformCustomFormulaJaql(jaql) {
|
|
|
98
98
|
return attribute;
|
|
99
99
|
}
|
|
100
100
|
/**
|
|
101
|
-
* Creates a calculated measure for a
|
|
101
|
+
* Creates a calculated measure for a valid custom formula built from [base functions](https://docs.sisense.com/main/SisenseLinux/dashboard-functions-reference.htm).
|
|
102
102
|
*
|
|
103
|
-
* Use square brackets within the `formula` to include dimensions or measures.
|
|
103
|
+
* Use square brackets (`[]`) within the `formula` property to include dimensions or measures.
|
|
104
104
|
* Each unique dimension or measure included in the `formula` must be defined using a property:value pair in the `context` parameter.
|
|
105
105
|
*
|
|
106
|
-
* You can nest custom formulas by placing one inside the `formula` parameter of another
|
|
106
|
+
* You can nest custom formulas by placing one inside the `formula` parameter of another.
|
|
107
107
|
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
108
|
+
* Note: [Shared formulas](https://docs.sisense.com/main/SisenseLinux/shared-formulas.htm) must be
|
|
109
|
+
* fetched prior to use (see {@link @sisense/sdk-ui!useGetSharedFormula | useGetSharedFormula}).
|
|
110
110
|
*
|
|
111
111
|
* @example
|
|
112
|
-
* An example of constructing a
|
|
113
|
-
*
|
|
114
|
-
*
|
|
112
|
+
* An example of constructing a custom formulas using dimensions, measures, and nested custom formulas
|
|
113
|
+
* from the Sample Ecommerce data model.
|
|
114
|
+
* ```ts
|
|
115
|
+
* // Custom formula
|
|
116
|
+
* const profitabilityRatio = measureFactory.customFormula(
|
|
115
117
|
* 'Profitability Ratio',
|
|
116
118
|
* '([totalRevenue] - SUM([cost])) / [totalRevenue]',
|
|
117
119
|
* {
|
|
118
|
-
* totalRevenue:
|
|
120
|
+
* totalRevenue: measureFactory.sum(DM.Commerce.Revenue),
|
|
119
121
|
* cost: DM.Commerce.Cost,
|
|
120
122
|
* },
|
|
121
123
|
* );
|
|
122
124
|
*
|
|
123
|
-
*
|
|
125
|
+
* // Nested custom formula
|
|
126
|
+
* const profitabilityRatioRank = measureFactory.customFormula(
|
|
124
127
|
* 'Profitability Ratio Rank',
|
|
125
128
|
* 'RANK([profRatio], "ASC", "1224")',
|
|
126
129
|
* {
|
|
127
130
|
* profRatio: profitabilityRatio,
|
|
128
131
|
* },
|
|
129
132
|
* );
|
|
130
|
-
*
|
|
131
|
-
* return (
|
|
132
|
-
* <Chart
|
|
133
|
-
* dataSet={DM.DataSource}
|
|
134
|
-
* chartType="line"
|
|
135
|
-
* dataOptions={{
|
|
136
|
-
* category: [DM.Commerce.AgeRange],
|
|
137
|
-
* value: [
|
|
138
|
-
* profitabilityRatioRank,
|
|
139
|
-
* {
|
|
140
|
-
* column: measures.sum(DM.Commerce.Revenue, 'Total Revenue'),
|
|
141
|
-
* showOnRightAxis: true,
|
|
142
|
-
* chartType: 'column',
|
|
143
|
-
* },
|
|
144
|
-
* {
|
|
145
|
-
* column: measures.sum(DM.Commerce.Cost, 'Total Cost'),
|
|
146
|
-
* showOnRightAxis: true,
|
|
147
|
-
* chartType: 'column',
|
|
148
|
-
* },
|
|
149
|
-
* ],
|
|
150
|
-
* }}
|
|
151
|
-
* />
|
|
152
|
-
* );
|
|
153
133
|
* ```
|
|
154
134
|
* @param title - Title of the measure to be displayed in legend
|
|
155
135
|
* @param formula - Formula to be used for the measure
|
|
156
136
|
* @param context - Formula context as a map of strings to measures or attributes
|
|
157
|
-
* @returns A calculated measure
|
|
137
|
+
* @returns A calculated measure instance
|
|
158
138
|
*/
|
|
159
139
|
export function customFormula(title, formula, context) {
|
|
160
140
|
const newContext = Object.entries(context).reduce((acc, [key, val]) => {
|
|
@@ -179,108 +159,153 @@ function arithmetic(operand1, operator, operand2, name, withParentheses) {
|
|
|
179
159
|
return new DimensionalCalculatedMeasure(name !== null && name !== void 0 ? name : exp, exp, context);
|
|
180
160
|
}
|
|
181
161
|
/**
|
|
182
|
-
* Creates
|
|
183
|
-
*
|
|
162
|
+
* Creates an aggregated measure.
|
|
163
|
+
*
|
|
164
|
+
* This is a base function to build other aggregation functions (e.g., `sum`, `average`, etc.)
|
|
184
165
|
* as listed in {@link AggregationTypes}.
|
|
185
166
|
*
|
|
167
|
+
* @example
|
|
168
|
+
* Calculate the total cost across all items in a category from the Sample Ecommerce data model.
|
|
169
|
+
* ```ts
|
|
170
|
+
* measureFactory.aggregate(DM.Commerce.Cost, 'sum'),
|
|
171
|
+
* ```
|
|
186
172
|
* @param attribute - Attribute to aggregate
|
|
187
173
|
* @param aggregationType - Aggregation type. See {@link AggregationTypes}
|
|
188
174
|
* @param name - Optional name for the new measure
|
|
189
|
-
* @param format -
|
|
190
|
-
* @returns A
|
|
175
|
+
* @param format - Optional numeric formatting to apply using a Numeral.js format string. Can only be used for explicit queries. Cannot be used in charts, tables, etc.
|
|
176
|
+
* @returns A measure instance
|
|
191
177
|
*/
|
|
192
178
|
export function aggregate(attribute, aggregationType, name, format) {
|
|
193
|
-
// if (aggregationType == AggregationTypes.Average || aggregationType == AggregationTypes.Max ||
|
|
194
|
-
// aggregationType == AggregationTypes.Min || aggregationType == AggregationTypes.Median ||
|
|
195
|
-
// aggregationType == AggregationTypes.Sum) {
|
|
196
|
-
// if (!MetadataTypes.isNumericDimension(attribute.type)) {
|
|
197
|
-
// throw `${aggregationType} is supported for numeric attributes only, where ${attribute.name} is ${attribute.type}`;
|
|
198
|
-
// }
|
|
199
|
-
// }
|
|
200
179
|
return new DimensionalBaseMeasure(name !== null && name !== void 0 ? name : `${aggregationType.toString()} ${attribute.name}`, attribute, aggregationType, format);
|
|
201
180
|
}
|
|
202
181
|
/**
|
|
203
|
-
*
|
|
182
|
+
* Creates a calculated measure from a numeric value.
|
|
204
183
|
*
|
|
184
|
+
* @example
|
|
185
|
+
* Creates a calculated measure from a numeric value.
|
|
186
|
+
* ```ts
|
|
187
|
+
* measureFactory.constant(42)
|
|
188
|
+
* ```
|
|
205
189
|
* @param value - Value to be returned as a measure
|
|
206
|
-
* @returns A
|
|
190
|
+
* @returns A calculated measure instance
|
|
207
191
|
*/
|
|
208
192
|
export function constant(value) {
|
|
209
193
|
return new DimensionalCalculatedMeasure(`${value}`, `${value}`, {});
|
|
210
194
|
}
|
|
211
195
|
/**
|
|
212
|
-
* Creates a sum aggregation over the given attribute.
|
|
196
|
+
* Creates a sum aggregation measure over the given attribute.
|
|
197
|
+
*
|
|
198
|
+
* To create a running sum, use {@link runningSum}.
|
|
213
199
|
*
|
|
200
|
+
* @example
|
|
201
|
+
* Calculate the total cost across all items in a category from the Sample Ecommerce data model.
|
|
202
|
+
* ```ts
|
|
203
|
+
* measureFactory.sum(DM.Commerce.Cost)
|
|
204
|
+
* ```
|
|
214
205
|
* @param attribute - Attribute to aggregate
|
|
215
206
|
* @param name - Optional name for the new measure
|
|
216
|
-
* @param format - Optional numeric formatting to apply
|
|
217
|
-
* @returns A
|
|
207
|
+
* @param format - Optional numeric formatting to apply using a Numeral.js format string. Can only be used for explicit queries. Cannot be used in charts, tables, etc.
|
|
208
|
+
* @returns A measure instance
|
|
218
209
|
*/
|
|
219
210
|
export function sum(attribute, name, format) {
|
|
220
211
|
return aggregate(attribute, AggregationTypes.Sum, name, format);
|
|
221
212
|
}
|
|
222
213
|
/**
|
|
223
|
-
* Creates an average aggregation over the given attribute.
|
|
214
|
+
* Creates an average aggregation measure over the given attribute.
|
|
224
215
|
*
|
|
216
|
+
* @example
|
|
217
|
+
* Calculate the average cost across all items in a category from the Sample Ecommerce data model.
|
|
218
|
+
* ```ts
|
|
219
|
+
* measureFactory.average(DM.Commerce.Cost)
|
|
220
|
+
* ```
|
|
225
221
|
* @param attribute - Attribute to aggregate
|
|
226
222
|
* @param name - Optional name for the new measure
|
|
227
|
-
* @param format - Optional numeric formatting to apply
|
|
228
|
-
* @returns A
|
|
223
|
+
* @param format - Optional numeric formatting to apply using a Numeral.js format string. Can only be used for explicit queries. Cannot be used in charts, tables, etc.
|
|
224
|
+
* @returns A measure instance
|
|
229
225
|
*/
|
|
230
226
|
export function average(attribute, name, format) {
|
|
231
227
|
return aggregate(attribute, AggregationTypes.Average, name, format);
|
|
232
228
|
}
|
|
233
229
|
/**
|
|
234
|
-
* Creates a min aggregation over the given attribute.
|
|
230
|
+
* Creates a min aggregation measure over the given attribute.
|
|
235
231
|
*
|
|
232
|
+
* @example
|
|
233
|
+
* Calculate the minimum cost across all items in a category from the Sample Ecommerce data model.
|
|
234
|
+
* ```ts
|
|
235
|
+
* measureFactory.min(DM.Commerce.Cost)
|
|
236
|
+
* ```
|
|
236
237
|
* @param attribute - Attribute to aggregate
|
|
237
238
|
* @param name - Optional name for the new measure
|
|
238
|
-
* @param format - Optional numeric formatting to apply
|
|
239
|
-
* @returns A
|
|
239
|
+
* @param format - Optional numeric formatting to apply using a Numeral.js format string. Can only be used for explicit queries. Cannot be used in charts, tables, etc.
|
|
240
|
+
* @returns A measure instance
|
|
240
241
|
*/
|
|
241
242
|
export function min(attribute, name, format) {
|
|
242
243
|
return aggregate(attribute, AggregationTypes.Min, name, format);
|
|
243
244
|
}
|
|
244
245
|
/**
|
|
245
|
-
* Creates a max aggregation over the given attribute.
|
|
246
|
+
* Creates a max aggregation measure over the given attribute.
|
|
246
247
|
*
|
|
248
|
+
* @example
|
|
249
|
+
* Calculate the maximum cost across all items in a category from the Sample Ecommerce data model.
|
|
250
|
+
* ```ts
|
|
251
|
+
* measureFactory.max(DM.Commerce.Cost)
|
|
252
|
+
* ```
|
|
247
253
|
* @param attribute - Attribute to aggregate
|
|
248
254
|
* @param name - Optional name for the new measure
|
|
249
|
-
* @param format - Optional numeric formatting to apply
|
|
250
|
-
* @returns A
|
|
255
|
+
* @param format - Optional numeric formatting to apply using a Numeral.js format string. Can only be used for explicit queries. Cannot be used in charts, tables, etc.
|
|
256
|
+
* @returns A measure instance
|
|
251
257
|
*/
|
|
252
258
|
export function max(attribute, name, format) {
|
|
253
259
|
return aggregate(attribute, AggregationTypes.Max, name, format);
|
|
254
260
|
}
|
|
255
261
|
/**
|
|
256
|
-
* Creates a median aggregation over the given attribute.
|
|
262
|
+
* Creates a median aggregation measure over the given attribute.
|
|
257
263
|
*
|
|
264
|
+
* @example
|
|
265
|
+
* Calculate the median cost across all items in a category from the Sample Ecommerce data model.
|
|
266
|
+
* ```ts
|
|
267
|
+
* measureFactory.median(DM.Commerce.Cost)
|
|
268
|
+
* ```
|
|
258
269
|
* @param attribute - Attribute to aggregate
|
|
259
270
|
* @param name - Optional name for the new measure
|
|
260
|
-
* @param format - Optional numeric formatting to apply
|
|
261
|
-
* @returns A
|
|
271
|
+
* @param format - Optional numeric formatting to apply using a Numeral.js format string. Can only be used for explicit queries. Cannot be used in charts, tables, etc.
|
|
272
|
+
* @returns A measure instance
|
|
262
273
|
*/
|
|
263
274
|
export function median(attribute, name, format) {
|
|
264
275
|
return aggregate(attribute, AggregationTypes.Median, name, format);
|
|
265
276
|
}
|
|
266
277
|
/**
|
|
267
|
-
* Creates a count aggregation over the given attribute.
|
|
278
|
+
* Creates a count aggregation measure over the given attribute.
|
|
279
|
+
*
|
|
280
|
+
* To count distinct values in the given attribute, use {@link countDistinct}.
|
|
268
281
|
*
|
|
282
|
+
* @example
|
|
283
|
+
* Counts the number of Commerce items from the Sample Ecommerce data model.
|
|
284
|
+
* ```ts
|
|
285
|
+
* measureFactory.count(DM.Commerce.BrandID)
|
|
286
|
+
* ```
|
|
269
287
|
* @param attribute - Attribute to aggregate
|
|
270
288
|
* @param name - Optional name for the new measure
|
|
271
|
-
* @param format - Optional numeric formatting to apply
|
|
272
|
-
* @returns A
|
|
289
|
+
* @param format - Optional numeric formatting to apply using a Numeral.js format string. Can only be used for explicit queries. Cannot be used in charts, tables, etc.
|
|
290
|
+
* @returns A measure instance
|
|
273
291
|
*/
|
|
274
292
|
export function count(attribute, name, format) {
|
|
275
293
|
return aggregate(attribute, AggregationTypes.Count, name, format);
|
|
276
294
|
}
|
|
277
295
|
/**
|
|
278
|
-
* Creates a count distinct aggregation over the given attribute.
|
|
296
|
+
* Creates a count distinct aggregation measure over the given attribute.
|
|
279
297
|
*
|
|
298
|
+
* To count all values in the given attribute, use {@link count}.
|
|
299
|
+
*
|
|
300
|
+
* @example
|
|
301
|
+
* Calculate the number of distinct brands from the Sample Ecommerce data model.
|
|
302
|
+
* ```ts
|
|
303
|
+
* measureFactory.countDistinct(DM.Brand.BrandID)
|
|
304
|
+
* ```
|
|
280
305
|
* @param attribute - Attribute to aggregate
|
|
281
306
|
* @param name - Optional name for the new measure
|
|
282
|
-
* @param format - Optional numeric formatting to apply
|
|
283
|
-
* @returns A
|
|
307
|
+
* @param format - Optional numeric formatting to apply using a Numeral.js format string. Can only be used for explicit queries. Cannot be used in charts, tables, etc.
|
|
308
|
+
* @returns A measure instance
|
|
284
309
|
*/
|
|
285
310
|
export function countDistinct(attribute, name, format) {
|
|
286
311
|
return aggregate(attribute, AggregationTypes.CountDistinct, name, format);
|
|
@@ -288,11 +313,28 @@ export function countDistinct(attribute, name, format) {
|
|
|
288
313
|
/**
|
|
289
314
|
* Creates a measured value with the given measure and set of filters.
|
|
290
315
|
*
|
|
316
|
+
* A measured value only includes values from items that match the provided filters.
|
|
317
|
+
*
|
|
318
|
+
* For example you can use a measured value to get a total cost for all items where the cost is greater than 100.
|
|
319
|
+
*
|
|
320
|
+
* Note that the filters on the measured value override the filters on the query, chart, or table the
|
|
321
|
+
* measured value is used in.
|
|
322
|
+
*
|
|
323
|
+
* @example
|
|
324
|
+
* Calculate the total cost across all items in a category from the Sample Ecommerce data model,
|
|
325
|
+
* where the cost is greater than 100. Additional filtering on the cost will not affect this measure.
|
|
326
|
+
* ```ts
|
|
327
|
+
* measureFactory.measuredValue(
|
|
328
|
+
* measureFactory.sum(DM.Commerce.Cost),
|
|
329
|
+
* [filters.greaterThan(DM.Commerce.Cost, 100)],
|
|
330
|
+
* 'Cost Greater Than 100'
|
|
331
|
+
* ),
|
|
332
|
+
* ```
|
|
291
333
|
* @param measure - Measure to filter
|
|
292
334
|
* @param filters - Filters to apply to the measure
|
|
293
335
|
* @param name - Optional name for the new measure
|
|
294
|
-
* @param format - Optional numeric formatting to apply
|
|
295
|
-
* @returns A
|
|
336
|
+
* @param format - Optional numeric formatting to apply using a Numeral.js format string. Can only be used for explicit queries. Cannot be used in charts, tables, etc.
|
|
337
|
+
* @returns A calculated measure instance
|
|
296
338
|
*/
|
|
297
339
|
export function measuredValue(measure, filters, name, format) {
|
|
298
340
|
const builder = [];
|
|
@@ -308,335 +350,607 @@ export function measuredValue(measure, filters, name, format) {
|
|
|
308
350
|
return new DimensionalCalculatedMeasure(name !== null && name !== void 0 ? name : exp, exp, context, format);
|
|
309
351
|
}
|
|
310
352
|
/**
|
|
311
|
-
*
|
|
353
|
+
* Creates a calculated measure by adding two given numbers or measures.
|
|
312
354
|
*
|
|
355
|
+
* @example
|
|
356
|
+
* ```ts
|
|
357
|
+
* const measure1 = measureFactory.sum(DM.Dimension.Attribute1);
|
|
358
|
+
* const measure2 = measureFactory.sum(DM.Dimension.Attribute2);
|
|
359
|
+
* const measureSum = measureFactory.add(measure1, measure2);
|
|
360
|
+
* ```
|
|
313
361
|
* @param value1 - First value
|
|
314
362
|
* @param value2 - Second value
|
|
315
363
|
* @param name - Optional name for the new measure
|
|
316
364
|
* @param withParentheses - Optional boolean flag whether to wrap the arithmetic operation with parentheses
|
|
317
|
-
* @returns A
|
|
365
|
+
* @returns A calculated measure instance
|
|
318
366
|
*/
|
|
319
367
|
export function add(value1, value2, name, withParentheses) {
|
|
320
368
|
return arithmetic(value1, '+', value2, name, withParentheses);
|
|
321
369
|
}
|
|
322
370
|
/**
|
|
323
|
-
*
|
|
371
|
+
* Creates a calculated measure by subtracting two given numbers or measures. Subtracts `value2` from `value1`.
|
|
324
372
|
*
|
|
373
|
+
* @example
|
|
374
|
+
* ```ts
|
|
375
|
+
* const measure1 = measureFactory.sum(DM.Dimension.Attribute1);
|
|
376
|
+
* const measure2 = measureFactory.sum(DM.Dimension.Attribute2);
|
|
377
|
+
* const measureDifference = measureFactory.subtract(measure1, measure2);
|
|
378
|
+
* ```
|
|
325
379
|
* @param value1 - First value
|
|
326
380
|
* @param value2 - Second value
|
|
327
381
|
* @param name - Optional name for the new measure
|
|
328
382
|
* @param withParentheses - Optional boolean flag whether to wrap the arithmetic operation with parentheses
|
|
329
|
-
* @returns A
|
|
383
|
+
* @returns A calculated measure instance
|
|
330
384
|
*/
|
|
331
385
|
export function subtract(value1, value2, name, withParentheses) {
|
|
332
386
|
return arithmetic(value1, '-', value2, name, withParentheses);
|
|
333
387
|
}
|
|
334
388
|
/**
|
|
335
|
-
*
|
|
389
|
+
* Creates a calculated measure by multiplying two given numbers or measures.
|
|
336
390
|
*
|
|
391
|
+
* @example
|
|
392
|
+
* ```ts
|
|
393
|
+
* const measure1 = measureFactory.sum(DM.Dimension.Attribute1);
|
|
394
|
+
* const measure2 = measureFactory.sum(DM.Dimension.Attribute2);
|
|
395
|
+
* const measureProduct = measureFactory.multiply(measure1, measure2);
|
|
396
|
+
* ```
|
|
337
397
|
* @param value1 - First value
|
|
338
398
|
* @param value2 - Second value
|
|
339
399
|
* @param name - Optional name for the new measure
|
|
340
400
|
* @param withParentheses - Optional boolean flag whether to wrap the arithmetic operation with parentheses
|
|
341
|
-
* @returns A
|
|
401
|
+
* @returns A calculated measure instance
|
|
342
402
|
*/
|
|
343
403
|
export function multiply(value1, value2, name, withParentheses) {
|
|
344
404
|
return arithmetic(value1, '*', value2, name, withParentheses);
|
|
345
405
|
}
|
|
346
406
|
/**
|
|
347
|
-
*
|
|
407
|
+
* Creates a calculated measure by dividing two given numbers or measures. Divides `value1` by `value2`.
|
|
348
408
|
*
|
|
409
|
+
* @example
|
|
410
|
+
* ```ts
|
|
411
|
+
* const measure1 = measureFactory.sum(DM.Dimension.Attribute1);
|
|
412
|
+
* const measure2 = measureFactory.sum(DM.Dimension.Attribute2);
|
|
413
|
+
* const measureQuotient = measureFactory.divide(measure1, measure2);
|
|
414
|
+
* ```
|
|
349
415
|
* @param value1 - First value
|
|
350
416
|
* @param value2 - Second value
|
|
351
417
|
* @param name - Optional name for the new measure
|
|
352
418
|
* @param withParentheses - Optional boolean flag whether to wrap the arithmetic operation with parentheses
|
|
353
|
-
* @returns A
|
|
419
|
+
* @returns A calculated measure instance
|
|
354
420
|
*/
|
|
355
421
|
export function divide(value1, value2, name, withParentheses) {
|
|
356
422
|
return arithmetic(value1, '/', value2, name, withParentheses);
|
|
357
423
|
}
|
|
358
424
|
/**
|
|
359
|
-
*
|
|
425
|
+
* Creates a calculated measure that calculates the running total starting from the beginning
|
|
426
|
+
* of the year up to the current day, week, month, or quarter.
|
|
427
|
+
*
|
|
428
|
+
* The time resolution is determined by the minimum date level of the date dimension in the query
|
|
429
|
+
* that uses the returned measure.
|
|
360
430
|
*
|
|
431
|
+
* @example
|
|
432
|
+
* Calculate the running total of total cost from the Sample Ecommerce data model, starting from the
|
|
433
|
+
* beginning of the year up to the current day, week, month, or quarter.
|
|
434
|
+
* ```ts
|
|
435
|
+
* measureFactory.yearToDateSum(measureFactory.sum(DM.Commerce.Cost))
|
|
436
|
+
* ```
|
|
361
437
|
* @param measure - Measure to apply the YTD Sum to
|
|
362
438
|
* @param name - Name for the new measure
|
|
363
|
-
* @returns A
|
|
439
|
+
* @returns A calculated measure instance
|
|
364
440
|
*/
|
|
365
441
|
export function yearToDateSum(measure, name) {
|
|
366
442
|
return measureFunction(measure, name !== null && name !== void 0 ? name : 'YTD ' + measure.name, 'YTDSum');
|
|
367
443
|
}
|
|
368
444
|
/**
|
|
369
|
-
*
|
|
370
|
-
*
|
|
445
|
+
* Creates a calculated measure that calculates the running total starting from the beginning
|
|
446
|
+
* of the quarter up to the current day, week, or month.
|
|
371
447
|
*
|
|
448
|
+
* The time resolution is determined by the minimum date level of the date dimension in the query
|
|
449
|
+
* that uses the returned measure.
|
|
450
|
+
*
|
|
451
|
+
* @example
|
|
452
|
+
* Calculate the running total of total cost from the Sample Ecommerce data model, starting from the
|
|
453
|
+
* beginning of the quarter up to the current day, week, or month.
|
|
454
|
+
* ```ts
|
|
455
|
+
* measureFactory.quarterToDateSum(measureFactory.sum(DM.Commerce.Cost))
|
|
456
|
+
* ```
|
|
372
457
|
* @param measure - Measure to apply the QTD Sum to
|
|
373
458
|
* @param name - Name for the new measure
|
|
374
|
-
* @returns A
|
|
459
|
+
* @returns A calculated measure instance
|
|
375
460
|
*/
|
|
376
461
|
export function quarterToDateSum(measure, name) {
|
|
377
462
|
return measureFunction(measure, name !== null && name !== void 0 ? name : 'QTD ' + name, 'QTDSum');
|
|
378
463
|
}
|
|
379
464
|
/**
|
|
380
|
-
*
|
|
381
|
-
*
|
|
465
|
+
* Creates a calculated measure that calculates the running total starting from the beginning
|
|
466
|
+
* of the month up to the current day or week.
|
|
467
|
+
*
|
|
468
|
+
* The time resolution is determined by the minimum date level of the date dimension in the query
|
|
469
|
+
* that uses the returned measure.
|
|
382
470
|
*
|
|
471
|
+
* @example
|
|
472
|
+
* Calculate the running total of total cost from the Sample Ecommerce data model, starting from the
|
|
473
|
+
* beginning of the month up to the current day or week.
|
|
474
|
+
* ```ts
|
|
475
|
+
* measureFactory.monthToDateSum(measureFactory.sum(DM.Commerce.Cost))
|
|
476
|
+
* ```
|
|
383
477
|
* @param measure - Measure to apply the MTD Sum to
|
|
384
478
|
* @param name - Name for the new measure
|
|
385
|
-
* @returns A
|
|
479
|
+
* @returns A calculated measure instance
|
|
386
480
|
*/
|
|
387
481
|
export function monthToDateSum(measure, name) {
|
|
388
482
|
return measureFunction(measure, name !== null && name !== void 0 ? name : 'MTD ' + measure.name, 'MTDSum');
|
|
389
483
|
}
|
|
390
484
|
/**
|
|
391
|
-
*
|
|
392
|
-
*
|
|
485
|
+
* Creates a calculated measure that calculates the running total starting from the beginning
|
|
486
|
+
* of the week up to the current day.
|
|
393
487
|
*
|
|
488
|
+
* The time resolution is determined by the minimum date level of the date dimension in the query
|
|
489
|
+
* that uses the returned measure.
|
|
490
|
+
*
|
|
491
|
+
* @example
|
|
492
|
+
* Calculate the running total of total cost from the Sample Ecommerce data model, starting from the
|
|
493
|
+
* beginning of the week up to the current day.
|
|
494
|
+
* ```ts
|
|
495
|
+
* measureFactory.weekToDateSum(measureFactory.sum(DM.Commerce.Cost))
|
|
496
|
+
* ```
|
|
394
497
|
* @param measure - Measure to apply the WTD Sum to
|
|
395
498
|
* @param name - Name for the new measure
|
|
396
|
-
* @returns A
|
|
499
|
+
* @returns A calculated measure instance
|
|
397
500
|
*/
|
|
398
501
|
export function weekToDateSum(measure, name) {
|
|
399
502
|
return measureFunction(measure, name !== null && name !== void 0 ? name : 'MTD ' + measure.name, 'WTDSum');
|
|
400
503
|
}
|
|
401
504
|
/**
|
|
402
|
-
*
|
|
403
|
-
* according to the current sorting order in the query.
|
|
505
|
+
* Creates a calculated measure that calculates the running total of a given measure.
|
|
404
506
|
*
|
|
405
|
-
*
|
|
406
|
-
* To accumulate by another order, the relevant measure should be added as an additional column and sorted.
|
|
507
|
+
* The running sum is calculated using the current sort order of the query it's used in.
|
|
407
508
|
*
|
|
408
|
-
*
|
|
409
|
-
*
|
|
509
|
+
* @example
|
|
510
|
+
* Calculate the running sum of the total cost from the Sample Ecommerce data model across all categories.
|
|
511
|
+
* ```ts
|
|
512
|
+
* measureFactory.runningSum(measureFactory.sum(DM.Commerce.Cost)),
|
|
513
|
+
* ```
|
|
410
514
|
*
|
|
411
|
-
*
|
|
515
|
+
* Running sum values from the Sample Ecommerce data model when categorizing by age range.
|
|
516
|
+
* | AgeRange | Cost | Running Cost |
|
|
517
|
+
* | --- | --- | --- |
|
|
518
|
+
* | 0-18 | 4.32M | 4.32M |
|
|
519
|
+
* | 19-24 | 8.66M | 12.98M |
|
|
520
|
+
* | 25-34 | 21.19M | 34.16M |
|
|
521
|
+
* | 35-44 | 23.64M | 57.8M |
|
|
522
|
+
* | 45-54 | 20.39M | 78.19M |
|
|
523
|
+
* | 55-64 | 11.82M | 90.01M |
|
|
524
|
+
* | 65+ | 17.26M | 107.27M |
|
|
525
|
+
* @param measure - Measure to apply the running sum to
|
|
412
526
|
* @param _continuous - Boolean flag whether to accumulate the sum continuously
|
|
413
|
-
* when there are two or more dimensions. The default value is
|
|
527
|
+
* when there are two or more dimensions. The default value is false.
|
|
414
528
|
* @param name - Name for the new measure
|
|
415
|
-
* @returns A
|
|
529
|
+
* @returns A calculated measure instance
|
|
416
530
|
*/
|
|
417
531
|
export function runningSum(measure, _continuous, name) {
|
|
418
532
|
return measureFunction(measure, name !== null && name !== void 0 ? name : 'Running Sum ' + measure.name, 'RSum');
|
|
419
533
|
}
|
|
420
534
|
/**
|
|
421
|
-
*
|
|
535
|
+
* Creates a calculated measure that calculates growth over a period of time.
|
|
422
536
|
*
|
|
423
|
-
*
|
|
537
|
+
* The time resolution is determined by the minimum date level of the date dimension in the query
|
|
538
|
+
* that uses the returned measure.
|
|
424
539
|
*
|
|
425
|
-
*
|
|
540
|
+
* Growth is calculated using the following formula: `(currentPeriod – previousPeriod) / previousPeriod`.
|
|
426
541
|
*
|
|
427
|
-
*
|
|
542
|
+
* For example, if this period the value is 12 and the previous period's value was 10, the growth for
|
|
543
|
+
* this period is 20%, returned as '0.2' (calculation: `(12 – 10) / 10 = 0.2`).
|
|
428
544
|
*
|
|
429
|
-
*
|
|
545
|
+
* If the previous period's value is greater than the current period, the growth will be negative.
|
|
430
546
|
*
|
|
431
|
-
*
|
|
547
|
+
* For example, if this period the value is 80, and the previous period's was 100, the growth for
|
|
548
|
+
* this period is -20%, returned as `-0.2` (calculation: `(80 – 100) / 100 = -0.2`).
|
|
432
549
|
*
|
|
433
|
-
*
|
|
550
|
+
* @example
|
|
551
|
+
* Calculate the growth in total cost this period in comparison to the previous period from the
|
|
552
|
+
* Sample Ecommerce data model.
|
|
553
|
+
* ```ts
|
|
554
|
+
* measureFactory.growth(measureFactory.sum(DM.Commerce.Cost))
|
|
555
|
+
* ```
|
|
434
556
|
* @param measure - Measure to apply growth to
|
|
435
557
|
* @param name - Name for the new measure
|
|
436
|
-
* @returns A
|
|
558
|
+
* @returns A calculated measure instance
|
|
437
559
|
*/
|
|
438
560
|
export function growth(measure, name) {
|
|
439
561
|
return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growth');
|
|
440
562
|
}
|
|
441
563
|
/**
|
|
442
|
-
*
|
|
564
|
+
* Creates a calculated measure that calculates growth rate over a period of time.
|
|
443
565
|
*
|
|
444
|
-
*
|
|
445
|
-
*
|
|
566
|
+
* The time resolution is determined by the minimum date level of the date dimension in the query
|
|
567
|
+
* that uses the returned measure.
|
|
446
568
|
*
|
|
447
|
-
*
|
|
569
|
+
* Growth rate is calculated using the following formula: `currentPeriod / previousPeriod`.
|
|
448
570
|
*
|
|
449
|
-
*
|
|
571
|
+
* For example, if this period the value is 12 and the previous period's value was 10, the growth rate for
|
|
572
|
+
* this period is 120%, returned as '1.2' (calculation: `12 / 10 = 1.2`).
|
|
450
573
|
*
|
|
451
|
-
*
|
|
574
|
+
* If the previous period's value is greater than the current period, the growth rate will be less than one.
|
|
575
|
+
*
|
|
576
|
+
* For example, if this period the value is 80, and the previous period's was 100, the growth for
|
|
577
|
+
* this period is 80%, returned as `0.8` (calculation: `80 / 100 = .8`).
|
|
578
|
+
*
|
|
579
|
+
* @example
|
|
580
|
+
* Calculate the growth rate in total cost this period in comparison to the previous period from the
|
|
581
|
+
* Sample Ecommerce data model.
|
|
582
|
+
* ```ts
|
|
583
|
+
* measureFactory.growthRate(measureFactory.sum(DM.Commerce.Cost))
|
|
584
|
+
* ```
|
|
452
585
|
* @param measure - Measure to apply the Growth rate
|
|
453
586
|
* @param name - Name for the new measure
|
|
454
|
-
* @returns A
|
|
587
|
+
* @returns A calculated measure instance
|
|
455
588
|
*/
|
|
456
589
|
export function growthRate(measure, name) {
|
|
457
590
|
return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growthrate');
|
|
458
591
|
}
|
|
459
592
|
/**
|
|
460
|
-
*
|
|
461
|
-
* Date dimension will be dynamically taken from the query.
|
|
593
|
+
* Creates a calculated measure that calculates the growth from the previous week to the current week.
|
|
462
594
|
*
|
|
595
|
+
* The date dimension will be dynamically taken from the query that uses the returned measure.
|
|
596
|
+
*
|
|
597
|
+
* Growth is calculated using the following formula: `(currentWeek – previousWeek) / previousWeek`.
|
|
598
|
+
*
|
|
599
|
+
* For example, if this week the value is 12 and the previous week's value was 10, the growth for
|
|
600
|
+
* this week is 20%, returned as '0.2' (calculation: `(12 – 10) / 10 = 0.2`).
|
|
601
|
+
*
|
|
602
|
+
* If the previous week's value is greater than the current week, the growth will be negative.
|
|
603
|
+
*
|
|
604
|
+
* For example, if this week the value is 80, and the previous week's was 100, the growth for
|
|
605
|
+
* this week is -20%, returned as `-0.2` (calculation: `(80 – 100) / 100 = -0.2`).
|
|
606
|
+
*
|
|
607
|
+
* @example
|
|
608
|
+
* Calculate the growth in total cost this week in comparison to the previous week from the Sample
|
|
609
|
+
* Ecommerce data model.
|
|
610
|
+
* ```ts
|
|
611
|
+
* measureFactory.growthPastWeek(measureFactory.sum(DM.Commerce.Cost))
|
|
612
|
+
* ```
|
|
463
613
|
* @param measure - Measure to apply growth to
|
|
464
614
|
* @param name - Name for the new measure
|
|
465
|
-
* @returns A
|
|
615
|
+
* @returns A calculated measure instance
|
|
466
616
|
*/
|
|
467
617
|
export function growthPastWeek(measure, name) {
|
|
468
618
|
return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growthpastweek');
|
|
469
619
|
}
|
|
470
620
|
/**
|
|
471
|
-
*
|
|
472
|
-
*
|
|
621
|
+
* Creates a calculated measure that calculates the growth from the previous month to the current month.
|
|
622
|
+
*
|
|
623
|
+
* The date dimension will be dynamically taken from the query that uses the returned measure.
|
|
473
624
|
*
|
|
625
|
+
* Growth is calculated using the following formula: `(currentMonth – previousMonth) / previousMonth`.
|
|
626
|
+
*
|
|
627
|
+
* For example, if this month the value is 12 and the previous month's value was 10, the growth for
|
|
628
|
+
* this month is 20%, returned as '0.2' (calculation: `(12 – 10) / 10 = 0.2`).
|
|
629
|
+
*
|
|
630
|
+
* If the previous month's value is greater than the current month, the growth will be negative.
|
|
631
|
+
*
|
|
632
|
+
* For example, if this month the value is 80, and the previous month's was 100, the growth for
|
|
633
|
+
* this month is -20%, returned as `-0.2` (calculation: `(80 – 100) / 100 = -0.2`).
|
|
634
|
+
*
|
|
635
|
+
* @example
|
|
636
|
+
* Calculate the growth in total cost this month in comparison to the previous month from the Sample
|
|
637
|
+
* Ecommerce data model.
|
|
638
|
+
* ```ts
|
|
639
|
+
* measureFactory.growthPastMonth(measureFactory.sum(DM.Commerce.Cost))
|
|
640
|
+
* ```
|
|
474
641
|
* @param measure - Measure to apply growth to
|
|
475
642
|
* @param name - Name for the new measure
|
|
476
|
-
* @returns A
|
|
643
|
+
* @returns A calculated measure instance
|
|
477
644
|
*/
|
|
478
645
|
export function growthPastMonth(measure, name) {
|
|
479
646
|
return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growthpastmonth');
|
|
480
647
|
}
|
|
481
648
|
/**
|
|
482
|
-
*
|
|
483
|
-
*
|
|
649
|
+
* Creates a calculated measure that calculates the growth from the previous quarter to the current quarter.
|
|
650
|
+
*
|
|
651
|
+
* The date dimension will be dynamically taken from the query that uses the returned measure.
|
|
652
|
+
*
|
|
653
|
+
* Growth is calculated using the following formula: `(currentQuarter – previousQuarter) / previousQuarter`.
|
|
654
|
+
*
|
|
655
|
+
* For example, if this quarter the value is 12 and the previous quarter's value was 10, the growth for
|
|
656
|
+
* this quarter is 20%, returned as '0.2' (calculation: `(12 – 10) / 10 = 0.2`).
|
|
484
657
|
*
|
|
658
|
+
* If the previous quarter's value is greater than the current quarter, the growth will be negative.
|
|
659
|
+
*
|
|
660
|
+
* For example, if this quarter the value is 80, and the previous quarter's was 100, the growth for
|
|
661
|
+
* this quarter is -20%, returned as `-0.2` (calculation: `(80 – 100) / 100 = -0.2`).
|
|
662
|
+
*
|
|
663
|
+
* @example
|
|
664
|
+
* Calculate the growth in total cost this quarter in comparison to the previous quarter from the
|
|
665
|
+
* Sample Ecommerce data model.
|
|
666
|
+
* ```ts
|
|
667
|
+
* measureFactory.growthPastQuarter(measureFactory.sum(DM.Commerce.Cost))
|
|
668
|
+
* ```
|
|
485
669
|
* @param measure - Measure to apply growth to
|
|
486
670
|
* @param name - Name for the new measure
|
|
487
|
-
* @returns A
|
|
671
|
+
* @returns A calculated measure instance
|
|
488
672
|
*/
|
|
489
673
|
export function growthPastQuarter(measure, name) {
|
|
490
674
|
return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growthpastquarter');
|
|
491
675
|
}
|
|
492
676
|
/**
|
|
493
|
-
*
|
|
494
|
-
*
|
|
677
|
+
* Creates a calculated measure that calculates the growth from the previous year to the current year.
|
|
678
|
+
*
|
|
679
|
+
* The date dimension will be dynamically taken from the query that uses the returned measure.
|
|
680
|
+
*
|
|
681
|
+
* Growth is calculated using the following formula: `(currentYear – previousYear) / previousYear`.
|
|
682
|
+
*
|
|
683
|
+
* For example, if this year the value is 12 and the previous year's value was 10, the growth for
|
|
684
|
+
* this year is 20%, returned as '0.2' (calculation: `(12 – 10) / 10 = 0.2`).
|
|
685
|
+
*
|
|
686
|
+
* If the previous year's value is greater than the current year, the growth will be negative.
|
|
495
687
|
*
|
|
688
|
+
* For example, if this year the value is 80, and the previous year's was 100, the growth for
|
|
689
|
+
* this year is -20%, returned as `-0.2` (calculation: `(80 – 100) / 100 = -0.2`).
|
|
690
|
+
*
|
|
691
|
+
* @example
|
|
692
|
+
* Calculate the growth in total cost this year in comparison to the previous year from the Sample
|
|
693
|
+
* Ecommerce data model.
|
|
694
|
+
* ```ts
|
|
695
|
+
* measureFactory.growthPastYear(measureFactory.sum(DM.Commerce.Cost))
|
|
696
|
+
* ```
|
|
496
697
|
* @param measure - Measure to apply growth to
|
|
497
698
|
* @param name - Name for the new measure
|
|
498
|
-
* @returns A
|
|
699
|
+
* @returns A calculated measure instance
|
|
499
700
|
*/
|
|
500
701
|
export function growthPastYear(measure, name) {
|
|
501
702
|
return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growthpastyear');
|
|
502
703
|
}
|
|
503
704
|
/**
|
|
504
|
-
*
|
|
505
|
-
*
|
|
705
|
+
* Creates a calculated measure that calculates the difference between this period's data
|
|
706
|
+
* and the data from the previous period for the given measure.
|
|
506
707
|
*
|
|
507
|
-
*
|
|
708
|
+
* The time resolution is determined by the minimum date level of the date dimension in the query
|
|
709
|
+
* that uses the returned measure.
|
|
710
|
+
*
|
|
711
|
+
* @example
|
|
712
|
+
* Calculate the difference between this period's total cost and the previous period's total cost
|
|
713
|
+
* from the Sample Ecommerce data model.
|
|
714
|
+
* ```ts
|
|
715
|
+
* measureFactory.difference(measureFactory.sum(DM.Commerce.Cost))
|
|
716
|
+
* ```
|
|
717
|
+
* @param measure - Measure to apply difference to
|
|
508
718
|
* @param name - Name for the new measure
|
|
509
|
-
* @returns A
|
|
719
|
+
* @returns A calculated measure instance
|
|
510
720
|
*/
|
|
511
721
|
export function difference(measure, name) {
|
|
512
722
|
return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Difference', 'diffpastperiod');
|
|
513
723
|
}
|
|
514
724
|
/**
|
|
515
|
-
*
|
|
516
|
-
*
|
|
725
|
+
* Creates a calculated measure that calculates the difference between this week's data
|
|
726
|
+
* and the data from the previous week for the given measure.
|
|
517
727
|
*
|
|
728
|
+
* The date dimension will be dynamically taken from the query that uses the returned measure.
|
|
729
|
+
*
|
|
730
|
+
* @example
|
|
731
|
+
* Calculate the difference between this week's total cost and the previous week's total cost from
|
|
732
|
+
* the Sample Ecommerce data model.
|
|
733
|
+
* ```ts
|
|
734
|
+
* measureFactory.diffPastWeek(measureFactory.sum(DM.Commerce.Cost))
|
|
735
|
+
* ```
|
|
518
736
|
* @param measure - Measure to apply difference to
|
|
519
737
|
* @param name - Name for the new measure
|
|
520
|
-
* @returns A
|
|
738
|
+
* @returns A calculated measure instance
|
|
521
739
|
*/
|
|
522
740
|
export function diffPastWeek(measure, name) {
|
|
523
741
|
return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Difference', 'diffpastweek');
|
|
524
742
|
}
|
|
525
743
|
/**
|
|
526
|
-
*
|
|
527
|
-
*
|
|
744
|
+
* Creates a calculated measure that calculates the difference between this month's data
|
|
745
|
+
* and the data from the previous month for the given measure.
|
|
746
|
+
*
|
|
747
|
+
* The date dimension will be dynamically taken from the query that uses the returned measure.
|
|
528
748
|
*
|
|
749
|
+
* @example
|
|
750
|
+
* Calculate the difference between this month's total cost and the previous month's total cost from
|
|
751
|
+
* the Sample Ecommerce data model.
|
|
752
|
+
* ```ts
|
|
753
|
+
* measureFactory.diffPastMonth(measureFactory.sum(DM.Commerce.Cost))
|
|
754
|
+
* ```
|
|
529
755
|
* @param measure - Measure to apply difference to
|
|
530
756
|
* @param name - Name for the new measure
|
|
531
|
-
* @returns A
|
|
757
|
+
* @returns A calculated measure instance
|
|
532
758
|
*/
|
|
533
759
|
export function diffPastMonth(measure, name) {
|
|
534
760
|
return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Difference', 'diffpastmonth');
|
|
535
761
|
}
|
|
536
762
|
/**
|
|
537
|
-
*
|
|
538
|
-
*
|
|
763
|
+
* Creates a calculated measure that calculates the difference between this quarter's data
|
|
764
|
+
* and the data from the previous quarter for the given measure.
|
|
539
765
|
*
|
|
766
|
+
* The date dimension will be dynamically taken from the query that uses the returned measure.
|
|
767
|
+
*
|
|
768
|
+
* @example
|
|
769
|
+
* Calculate the difference between this quarter's total cost and the previous quarter's total cost
|
|
770
|
+
* from the Sample Ecommerce data model.
|
|
771
|
+
* ```ts
|
|
772
|
+
* measureFactory.diffPastQuarter(measureFactory.sum(DM.Commerce.Cost))
|
|
773
|
+
* ```
|
|
540
774
|
* @param measure - Measure to apply difference to
|
|
541
775
|
* @param name - Name for the new measure
|
|
542
|
-
* @returns A
|
|
776
|
+
* @returns A calculated measure instance
|
|
543
777
|
*/
|
|
544
778
|
export function diffPastQuarter(measure, name) {
|
|
545
779
|
return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Difference', 'diffpastquarter');
|
|
546
780
|
}
|
|
547
781
|
/**
|
|
548
|
-
*
|
|
549
|
-
*
|
|
782
|
+
* Creates a calculated measure that calculates the difference between this year's data
|
|
783
|
+
* and the data from the previous year for the given measure.
|
|
784
|
+
*
|
|
785
|
+
* The date dimension will be dynamically taken from the query that uses the returned measure.
|
|
550
786
|
*
|
|
787
|
+
* @example
|
|
788
|
+
* Calculate the difference between this year's total cost and the previous year's total cost from
|
|
789
|
+
* the Sample Ecommerce data model.
|
|
790
|
+
* ```ts
|
|
791
|
+
* measureFactory.diffPastYear(measureFactory.sum(DM.Commerce.Cost))
|
|
792
|
+
* ```
|
|
551
793
|
* @param measure - Measure to apply difference to
|
|
552
794
|
* @param name - Name for the new measure
|
|
553
|
-
* @returns A
|
|
795
|
+
* @returns A calculated measure instance
|
|
554
796
|
*/
|
|
555
797
|
export function diffPastYear(measure, name) {
|
|
556
798
|
return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Difference', 'diffpastyear');
|
|
557
799
|
}
|
|
558
800
|
/**
|
|
559
|
-
*
|
|
560
|
-
* Date dimension will be dynamically taken from the query.
|
|
801
|
+
* Creates a calculated measure that calculates the value for the previous day.
|
|
561
802
|
*
|
|
803
|
+
* @example
|
|
804
|
+
* Calculate total cost for the previous day from the Sample Ecommerce data model.
|
|
805
|
+
* ```ts
|
|
806
|
+
* measureFactory.pastDay(measureFactory.sum(DM.Commerce.Cost))
|
|
807
|
+
* ```
|
|
562
808
|
* @param measure - Measure to apply past value to
|
|
563
809
|
* @param name - Name for the new measure
|
|
564
|
-
* @returns A
|
|
810
|
+
* @returns A calculated measure instance
|
|
565
811
|
*/
|
|
566
812
|
export function pastDay(measure, name) {
|
|
567
813
|
return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Past Day', 'pastday');
|
|
568
814
|
}
|
|
569
815
|
/**
|
|
570
|
-
*
|
|
571
|
-
*
|
|
816
|
+
* Creates a calculated measure that calculates the value for the same day in the previous week.
|
|
817
|
+
*
|
|
818
|
+
* The time resolution is determined by the minimum date level of the date dimension in the query
|
|
819
|
+
* that uses the returned measure.
|
|
572
820
|
*
|
|
821
|
+
* @example
|
|
822
|
+
* Calculate total cost for the corresponding day one week ago from the Sample Ecommerce data model.
|
|
823
|
+
* ```ts
|
|
824
|
+
* measureFactory.pastWeek(measureFactory.sum(DM.Commerce.Cost))
|
|
825
|
+
* ```
|
|
573
826
|
* @param measure - Measure to apply past value to
|
|
574
827
|
* @param name - Name for the new measure
|
|
575
|
-
* @returns A
|
|
828
|
+
* @returns A calculated measure instance
|
|
576
829
|
*/
|
|
577
830
|
export function pastWeek(measure, name) {
|
|
578
831
|
return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Past Week', 'pastweek');
|
|
579
832
|
}
|
|
580
833
|
/**
|
|
581
|
-
*
|
|
582
|
-
* Date dimension will be dynamically taken from the query.
|
|
834
|
+
* Creates a calculated measure that calculates the value for the same day or week in the previous month.
|
|
583
835
|
*
|
|
836
|
+
* The time resolution is determined by the minimum date level of the date dimension in the query
|
|
837
|
+
* that uses the returned measure.
|
|
838
|
+
*
|
|
839
|
+
* @example
|
|
840
|
+
* Calculate total cost for the corresponding day or week one month ago from the Sample Ecommerce
|
|
841
|
+
* data model.
|
|
842
|
+
* ```ts
|
|
843
|
+
* measureFactory.pastMonth(measureFactory.sum(DM.Commerce.Cost))
|
|
844
|
+
* ```
|
|
584
845
|
* @param measure - Measure to apply past value to
|
|
585
846
|
* @param name - Name for the new measure
|
|
586
|
-
* @returns A
|
|
847
|
+
* @returns A calculated measure instance
|
|
587
848
|
*/
|
|
588
849
|
export function pastMonth(measure, name) {
|
|
589
850
|
return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Past Month', 'pastmonth');
|
|
590
851
|
}
|
|
591
852
|
/**
|
|
592
|
-
*
|
|
593
|
-
*
|
|
853
|
+
* Creates a calculated measure that calculates the value for the same day, week, or month in the previous quarter.
|
|
854
|
+
*
|
|
855
|
+
* The time resolution is determined by the minimum date level of the date dimension in the query
|
|
856
|
+
* that uses the returned measure.
|
|
594
857
|
*
|
|
858
|
+
* @example
|
|
859
|
+
* Calculate total cost for the corresponding day, week, or month one quarter ago from the Sample
|
|
860
|
+
* Ecommerce data model.
|
|
861
|
+
* ```ts
|
|
862
|
+
* measureFactory.pastQuarter(measureFactory.sum(DM.Commerce.Cost))
|
|
863
|
+
* ```
|
|
595
864
|
* @param measure - Measure to apply past value to
|
|
596
865
|
* @param name - Name for the new measure
|
|
597
|
-
* @returns A
|
|
866
|
+
* @returns A calculated measure instance
|
|
598
867
|
*/
|
|
599
868
|
export function pastQuarter(measure, name) {
|
|
600
869
|
return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Past Quarter', 'pastquarter');
|
|
601
870
|
}
|
|
602
871
|
/**
|
|
603
|
-
*
|
|
604
|
-
* Date dimension will be dynamically taken from the query.
|
|
872
|
+
* Creates a calculated measure that calculates the value for the same day, week, month, or quarter in the previous year.
|
|
605
873
|
*
|
|
874
|
+
* The time resolution is determined by the minimum date level of the date dimension in the query
|
|
875
|
+
* that uses the returned measure.
|
|
876
|
+
*
|
|
877
|
+
* @example
|
|
878
|
+
* Calculate total cost for the corresponding day, week, month, or quarter one year ago from the
|
|
879
|
+
* Sample Ecommerce data model.
|
|
880
|
+
* ```ts
|
|
881
|
+
* measureFactory.pastYear(measureFactory.sum(DM.Commerce.Cost))
|
|
882
|
+
* ```
|
|
606
883
|
* @param measure - Measure to apply past value to
|
|
607
884
|
* @param name - Name for the new measure
|
|
608
|
-
* @returns A
|
|
885
|
+
* @returns A calculated measure instance
|
|
609
886
|
*/
|
|
610
887
|
export function pastYear(measure, name) {
|
|
611
888
|
return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Past Year', 'pastyear');
|
|
612
889
|
}
|
|
613
890
|
/**
|
|
614
|
-
*
|
|
891
|
+
* Creates a calculated contribution measure.
|
|
892
|
+
*
|
|
893
|
+
* A contribution measure calculates the contribution, in percentage, of a measure towards the total.
|
|
894
|
+
* Percentages are expressed as a number between 0 and 1 (e.g. 42% is `0.42`).
|
|
615
895
|
*
|
|
896
|
+
* For example, using the Sample Ecommerce data model you can retrieve the total cost of products
|
|
897
|
+
* categorized by age range. Using a contribution measure you can calculate how much each age range's
|
|
898
|
+
* total cost contributes to the total cost across all age ranges. So, the total cost for the 35-44
|
|
899
|
+
* age range is 23.64M, which is 22% of the 107.27M of all age ranges together. Therefore, the
|
|
900
|
+
* contribution of the 35-44 age range is `.22`.
|
|
901
|
+
*
|
|
902
|
+
* @example
|
|
903
|
+
* Calculates the percentage of the total cost across all categories for items in a category from the
|
|
904
|
+
* Sample Ecommerce data model.
|
|
905
|
+
* ```ts
|
|
906
|
+
* measureFactory.contribution(measureFactory.sum(DM.Commerce.Cost))
|
|
907
|
+
* ```
|
|
908
|
+
*
|
|
909
|
+
* Contribution values from the Sample Ecommerce data model when categorizing by age range.
|
|
910
|
+
* | AgeRange | Cost | Contribution |
|
|
911
|
+
* | --- | --- | --- |
|
|
912
|
+
* | 0-18 | 4.32M | 0.04 |
|
|
913
|
+
* | 19-24 | 8.66M | 0.08 |
|
|
914
|
+
* | 25-34 | 21.19M | 0.2 |
|
|
915
|
+
* | 35-44 | 23.64M | 0.22 |
|
|
916
|
+
* | 45-54 | 20.39M | 0.19 |
|
|
917
|
+
* | 55-64 | 11.82M | 0.11 |
|
|
918
|
+
* | 65+ | 17.26M | 0.16 |
|
|
616
919
|
* @param measure - Measure to apply the Contribution logic to
|
|
617
920
|
* @param name - Name for the new measure
|
|
618
|
-
* @returns A
|
|
921
|
+
* @returns A calculated measure instance
|
|
619
922
|
*/
|
|
620
923
|
export function contribution(measure, name) {
|
|
621
924
|
return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Contribution', 'contribution');
|
|
622
925
|
}
|
|
623
926
|
/**
|
|
624
|
-
*
|
|
625
|
-
*
|
|
626
|
-
*
|
|
927
|
+
* Creates a calculated measure that computes a specified trend type for a given measure.
|
|
928
|
+
*
|
|
929
|
+
* The trend types include linear (the default), logarithmic, advanced smoothing, and local estimates.
|
|
930
|
+
* You can also opt to automatically identify and ignore anomalous values in the series.
|
|
627
931
|
*
|
|
628
932
|
* Trend requires a Sisense instance version of L2023.6.0 or greater.
|
|
629
933
|
*
|
|
934
|
+
* @example
|
|
935
|
+
* Calculate the trend in total cost from the Sample Ecommerce data model.
|
|
936
|
+
* ```ts
|
|
937
|
+
* measureFactory.trend(
|
|
938
|
+
* measureFactory.sum(DM.Commerce.Cost),
|
|
939
|
+
* 'Total Cost Trend',
|
|
940
|
+
* {
|
|
941
|
+
* modelType: 'advancedSmoothing',
|
|
942
|
+
* ignoreAnomalies: true,
|
|
943
|
+
* }
|
|
944
|
+
* )
|
|
945
|
+
* ```
|
|
630
946
|
* @param measure - Measure to apply the trend logic to
|
|
631
947
|
* @param name - Name for the new measure
|
|
632
948
|
* @param options - Trend options
|
|
633
|
-
* @returns A
|
|
949
|
+
* @returns A calculated measure instance
|
|
634
950
|
*/
|
|
635
951
|
export function trend(measure, name, options) {
|
|
636
952
|
let params;
|
|
637
|
-
const adjustValues = (value) => value
|
|
638
|
-
.replace('advancedSmoothing', 'Advanced Smoothing')
|
|
639
|
-
.replace('localEstimates', 'Local Estimates');
|
|
953
|
+
const adjustValues = (value) => value.replace('advancedSmoothing', 'smooth').replace('localEstimates', 'local');
|
|
640
954
|
if (options) {
|
|
641
955
|
// make a comma separated name=value string based on options
|
|
642
956
|
params = Object.entries(options)
|
|
@@ -647,30 +961,43 @@ export function trend(measure, name, options) {
|
|
|
647
961
|
return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Trend', 'trend', params);
|
|
648
962
|
}
|
|
649
963
|
/**
|
|
650
|
-
*
|
|
651
|
-
*
|
|
964
|
+
* Creates a calculated measure that generates a forecast based on a specified measure employing
|
|
965
|
+
* advanced autoML techniques.
|
|
652
966
|
*
|
|
653
|
-
* This function offers
|
|
654
|
-
* statistical model or
|
|
655
|
-
*
|
|
656
|
-
* improve forecast accuracy by supplying expected lower and upper limits.
|
|
967
|
+
* This function offers flexible options allowing you to:
|
|
968
|
+
* + Let the function auto-select the best statistical model or explicitly choose a preferred model
|
|
969
|
+
* + Control the time period used for training the model
|
|
970
|
+
* + Set additional options to improve forecast accuracy by supplying expected lower and upper limits.
|
|
657
971
|
*
|
|
658
|
-
* In addition to forecast, upper and lower confidence
|
|
972
|
+
* In addition to the forecast, upper and lower confidence intervals are returned
|
|
659
973
|
* with the name of the new measure and a suffix of _upper and _lower
|
|
660
974
|
* respectively.
|
|
661
975
|
*
|
|
662
976
|
* Forecast requires a Sisense instance version of L2023.6.0 or greater.
|
|
663
977
|
*
|
|
978
|
+
* @example
|
|
979
|
+
* Calculate a forecast for total cost from the Sample Ecommerce data model from the Sample
|
|
980
|
+
* Ecommerce data model.
|
|
981
|
+
* ```ts
|
|
982
|
+
* measureFactory.forecast(
|
|
983
|
+
* measureFactory.sum(DM.Commerce.Cost),
|
|
984
|
+
* 'Total Cost Forecast',
|
|
985
|
+
* {
|
|
986
|
+
* modelType: 'prophet',
|
|
987
|
+
* roundToInt: true,
|
|
988
|
+
* }
|
|
989
|
+
* )
|
|
990
|
+
* ```
|
|
664
991
|
* @param measure - Measure to apply the forecast logic to
|
|
665
992
|
* @param name - Name for the new measure
|
|
666
993
|
* @param options - Forecast options
|
|
667
|
-
* @returns A
|
|
994
|
+
* @returns A calculated measure instance
|
|
668
995
|
*/
|
|
669
996
|
export function forecast(measure, name, options) {
|
|
670
997
|
let params;
|
|
671
998
|
if (options) {
|
|
672
999
|
// create ISO string values for any Date objects
|
|
673
|
-
const adjustedOptions = Object.assign({}, options);
|
|
1000
|
+
const adjustedOptions = Object.assign({ forecastHorizon: 3 }, options);
|
|
674
1001
|
if (adjustedOptions.startDate) {
|
|
675
1002
|
const startDate = new Date(adjustedOptions.startDate);
|
|
676
1003
|
adjustedOptions.startDate = startDate.toISOString().replace(/.\d+Z$/g, '');
|
|
@@ -691,19 +1018,53 @@ export function forecast(measure, name, options) {
|
|
|
691
1018
|
return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Forecast', 'forecast', params);
|
|
692
1019
|
}
|
|
693
1020
|
/**
|
|
694
|
-
*
|
|
1021
|
+
* Creates a calculated measure that calculates the rank of a value in a list of values.
|
|
1022
|
+
*
|
|
1023
|
+
* This function includes options that allow you do customize the ranking order and how to handle
|
|
1024
|
+
* equally ranked items.
|
|
1025
|
+
*
|
|
1026
|
+
* The order options are:
|
|
1027
|
+
* + `'DESC'` (default): Descending, meaning the largest number is ranked first.
|
|
1028
|
+
* + `'ASC'`: Ascending, meaning the smallest number is ranked first.
|
|
1029
|
+
*
|
|
1030
|
+
* The rank type options are:
|
|
1031
|
+
* + `'1224'`: Standard competition, meaning items that rank equally receive the same ranking number,
|
|
1032
|
+
* and then a gap is left after the equally ranked items in the ranking numbers.
|
|
1033
|
+
* + `'1334'`: Modified competition ranking, meaning items that rank equally receive the same ranking number,
|
|
1034
|
+
* and a gap is left before the equally ranked items in the ranking numbers.
|
|
1035
|
+
* + `'1223'`: Dense ranking, meaning items that rank equally receive the same ranking number,
|
|
1036
|
+
* and the next items receive the immediately following ranking number.
|
|
1037
|
+
* + `'1234'`: Ordinal ranking, meaning all items receive distinct ordinal numbers,
|
|
1038
|
+
* including items that rank equally. The assignment of distinct ordinal numbers for equal-ranking items is arbitrary.
|
|
695
1039
|
*
|
|
696
1040
|
* @example
|
|
697
|
-
*
|
|
698
|
-
*
|
|
699
|
-
*
|
|
1041
|
+
* Calculate the rank of the total cost per category, sorted with the smallest cost ranked first,
|
|
1042
|
+
* and ranking ties are handled using the ordinal ranking type from the Sample Ecommerce data model.
|
|
1043
|
+
* ```ts
|
|
1044
|
+
* measureFactory.rank(
|
|
1045
|
+
* measureFactory.sum(DM.Commerce.Cost),
|
|
1046
|
+
* 'Cost Rank',
|
|
1047
|
+
* measureFactory.RankingSortTypes.Ascending,
|
|
1048
|
+
* measureFactory.RankingTypes.Ordinal
|
|
1049
|
+
* )
|
|
1050
|
+
* ```
|
|
1051
|
+
*
|
|
1052
|
+
* Ranking values from the Sample Ecommerce data model when categorizing by age range using the above ranking.
|
|
1053
|
+
* | AgeRange | Cost | Cost Rank |
|
|
1054
|
+
* | --- | --- | --- |
|
|
1055
|
+
* | 0-18 | 4.32M | 1 |
|
|
1056
|
+
* | 19-24 | 8.66M | 2 |
|
|
1057
|
+
* | 25-34 | 21.19M | 6 |
|
|
1058
|
+
* | 35-44 | 23.64M | 7 |
|
|
1059
|
+
* | 45-54 | 20.39M | 5 |
|
|
1060
|
+
* | 55-64 | 11.82M | 3 |
|
|
1061
|
+
* | 65+ | 17.26M | 4 |
|
|
1062
|
+
* @param measure - Measure to apply the ranking logic to
|
|
700
1063
|
* @param name - Name for the new measure
|
|
701
|
-
* @param sort - By default sort order is descending.
|
|
702
|
-
* @param rankType - By default the type is standard competition ranking
|
|
703
|
-
*
|
|
704
|
-
*
|
|
705
|
-
* @param groupBy - Rank partitions attributes
|
|
706
|
-
* @returns A rank measure
|
|
1064
|
+
* @param sort - Sorting for ranking. By default sort order is descending, where the largest number is ranked first.
|
|
1065
|
+
* @param rankType - How to handle equally ranked items. By default the type is standard competition ranking.
|
|
1066
|
+
* @param groupBy - Rank partition attributes
|
|
1067
|
+
* @returns A calculated measure instance
|
|
707
1068
|
*/
|
|
708
1069
|
export function rank(measure, name, sort = RankingSortTypes.Descending, rankType = RankingTypes.StandardCompetition, groupBy = []) {
|
|
709
1070
|
const builder = [];
|