@sisense/sdk-data 0.16.0 → 1.1.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.
@@ -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 compare equal receive the same ranking number, and then a gap is left in the ranking numbers.
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
- * Sometimes, competition ranking is done by leaving the gaps in the ranking numbers before the sets of equal-ranking items (rather than after them as in standard competition ranking)
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 compare equally receive the same ranking number, and the next items receive the immediately following ranking number.
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 compare equal. The assignment of distinct ordinal numbers is arbitrarily.
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 [valid custom formula](https://docs.sisense.com/main/SisenseLinux/dashboard-functions-reference.htm).
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
- * Note: Shared formula must be fetched prior to use (see {@link @sisense/sdk-ui!useGetSharedFormula | useGetSharedFormula}).
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 `customFormula` using dimensions, measures, and nested custom formulas:
113
- * ```tsx
114
- * const profitabilityRatio = measures.customFormula(
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: measures.sum(DM.Commerce.Revenue),
120
+ * totalRevenue: measureFactory.sum(DM.Commerce.Revenue),
119
121
  * cost: DM.Commerce.Cost,
120
122
  * },
121
123
  * );
122
124
  *
123
- * const profitabilityRatioRank = measures.customFormula(
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 object that may be used in a chart or a query
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,101 +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 a basic aggregated measure.
183
- * This is a base function to build other aggregation functions (e.g., `sum`, `average`, etc)
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 - Numeric formatting to apply
190
- * @returns A Measure instance
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
179
  return new DimensionalBaseMeasure(name !== null && name !== void 0 ? name : `${aggregationType.toString()} ${attribute.name}`, attribute, aggregationType, format);
194
180
  }
195
181
  /**
196
- * Returns a numeric value as a measure.
182
+ * Creates a calculated measure from a numeric value.
197
183
  *
184
+ * @example
185
+ * Creates a calculated measure from a numeric value.
186
+ * ```ts
187
+ * measureFactory.constant(42)
188
+ * ```
198
189
  * @param value - Value to be returned as a measure
199
- * @returns A Calculated Measure instance
190
+ * @returns A calculated measure instance
200
191
  */
201
192
  export function constant(value) {
202
193
  return new DimensionalCalculatedMeasure(`${value}`, `${value}`, {});
203
194
  }
204
195
  /**
205
- * 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}.
206
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
+ * ```
207
205
  * @param attribute - Attribute to aggregate
208
206
  * @param name - Optional name for the new measure
209
- * @param format - Optional numeric formatting to apply
210
- * @returns A Measure instance
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
211
209
  */
212
210
  export function sum(attribute, name, format) {
213
211
  return aggregate(attribute, AggregationTypes.Sum, name, format);
214
212
  }
215
213
  /**
216
- * Creates an average aggregation over the given attribute.
214
+ * Creates an average aggregation measure over the given attribute.
217
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
+ * ```
218
221
  * @param attribute - Attribute to aggregate
219
222
  * @param name - Optional name for the new measure
220
- * @param format - Optional numeric formatting to apply
221
- * @returns A Measure instance
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
222
225
  */
223
226
  export function average(attribute, name, format) {
224
227
  return aggregate(attribute, AggregationTypes.Average, name, format);
225
228
  }
226
229
  /**
227
- * Creates a min aggregation over the given attribute.
230
+ * Creates a min aggregation measure over the given attribute.
228
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
+ * ```
229
237
  * @param attribute - Attribute to aggregate
230
238
  * @param name - Optional name for the new measure
231
- * @param format - Optional numeric formatting to apply
232
- * @returns A Measure instance
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
233
241
  */
234
242
  export function min(attribute, name, format) {
235
243
  return aggregate(attribute, AggregationTypes.Min, name, format);
236
244
  }
237
245
  /**
238
- * Creates a max aggregation over the given attribute.
246
+ * Creates a max aggregation measure over the given attribute.
239
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
+ * ```
240
253
  * @param attribute - Attribute to aggregate
241
254
  * @param name - Optional name for the new measure
242
- * @param format - Optional numeric formatting to apply
243
- * @returns A Measure instance
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
244
257
  */
245
258
  export function max(attribute, name, format) {
246
259
  return aggregate(attribute, AggregationTypes.Max, name, format);
247
260
  }
248
261
  /**
249
- * Creates a median aggregation over the given attribute.
262
+ * Creates a median aggregation measure over the given attribute.
250
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
+ * ```
251
269
  * @param attribute - Attribute to aggregate
252
270
  * @param name - Optional name for the new measure
253
- * @param format - Optional numeric formatting to apply
254
- * @returns A Measure instance
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
255
273
  */
256
274
  export function median(attribute, name, format) {
257
275
  return aggregate(attribute, AggregationTypes.Median, name, format);
258
276
  }
259
277
  /**
260
- * 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}.
261
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
+ * ```
262
287
  * @param attribute - Attribute to aggregate
263
288
  * @param name - Optional name for the new measure
264
- * @param format - Optional numeric formatting to apply
265
- * @returns A Measure instance
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
266
291
  */
267
292
  export function count(attribute, name, format) {
268
293
  return aggregate(attribute, AggregationTypes.Count, name, format);
269
294
  }
270
295
  /**
271
- * Creates a count distinct aggregation over the given attribute.
296
+ * Creates a count distinct aggregation measure over the given attribute.
272
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
+ * ```
273
305
  * @param attribute - Attribute to aggregate
274
306
  * @param name - Optional name for the new measure
275
- * @param format - Optional numeric formatting to apply
276
- * @returns A Measure instance
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
277
309
  */
278
310
  export function countDistinct(attribute, name, format) {
279
311
  return aggregate(attribute, AggregationTypes.CountDistinct, name, format);
@@ -281,11 +313,28 @@ export function countDistinct(attribute, name, format) {
281
313
  /**
282
314
  * Creates a measured value with the given measure and set of filters.
283
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
+ * ```
284
333
  * @param measure - Measure to filter
285
334
  * @param filters - Filters to apply to the measure
286
335
  * @param name - Optional name for the new measure
287
- * @param format - Optional numeric formatting to apply
288
- * @returns A Calculated Measure instance
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
289
338
  */
290
339
  export function measuredValue(measure, filters, name, format) {
291
340
  const builder = [];
@@ -301,329 +350,603 @@ export function measuredValue(measure, filters, name, format) {
301
350
  return new DimensionalCalculatedMeasure(name !== null && name !== void 0 ? name : exp, exp, context, format);
302
351
  }
303
352
  /**
304
- * Adds the two given values.
353
+ * Creates a calculated measure by adding two given numbers or measures.
305
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
+ * ```
306
361
  * @param value1 - First value
307
362
  * @param value2 - Second value
308
363
  * @param name - Optional name for the new measure
309
364
  * @param withParentheses - Optional boolean flag whether to wrap the arithmetic operation with parentheses
310
- * @returns A Calculated Measure instance
365
+ * @returns A calculated measure instance
311
366
  */
312
367
  export function add(value1, value2, name, withParentheses) {
313
368
  return arithmetic(value1, '+', value2, name, withParentheses);
314
369
  }
315
370
  /**
316
- * Subtract value2 from value1.
371
+ * Creates a calculated measure by subtracting two given numbers or measures. Subtracts `value2` from `value1`.
317
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
+ * ```
318
379
  * @param value1 - First value
319
380
  * @param value2 - Second value
320
381
  * @param name - Optional name for the new measure
321
382
  * @param withParentheses - Optional boolean flag whether to wrap the arithmetic operation with parentheses
322
- * @returns A Calculated Measure instance
383
+ * @returns A calculated measure instance
323
384
  */
324
385
  export function subtract(value1, value2, name, withParentheses) {
325
386
  return arithmetic(value1, '-', value2, name, withParentheses);
326
387
  }
327
388
  /**
328
- * Multiply value1 with value2.
389
+ * Creates a calculated measure by multiplying two given numbers or measures.
329
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
+ * ```
330
397
  * @param value1 - First value
331
398
  * @param value2 - Second value
332
399
  * @param name - Optional name for the new measure
333
400
  * @param withParentheses - Optional boolean flag whether to wrap the arithmetic operation with parentheses
334
- * @returns A Calculated Measure instance
401
+ * @returns A calculated measure instance
335
402
  */
336
403
  export function multiply(value1, value2, name, withParentheses) {
337
404
  return arithmetic(value1, '*', value2, name, withParentheses);
338
405
  }
339
406
  /**
340
- * Divide value1 by value2.
407
+ * Creates a calculated measure by dividing two given numbers or measures. Divides `value1` by `value2`.
341
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
+ * ```
342
415
  * @param value1 - First value
343
416
  * @param value2 - Second value
344
417
  * @param name - Optional name for the new measure
345
418
  * @param withParentheses - Optional boolean flag whether to wrap the arithmetic operation with parentheses
346
- * @returns A Calculated Measure instance
419
+ * @returns A calculated measure instance
347
420
  */
348
421
  export function divide(value1, value2, name, withParentheses) {
349
422
  return arithmetic(value1, '/', value2, name, withParentheses);
350
423
  }
351
424
  /**
352
- * Calculates year to date (YTD) sum of the given measure. Date dimension will be dynamically taken from the query.
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.
353
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
+ * ```
354
437
  * @param measure - Measure to apply the YTD Sum to
355
438
  * @param name - Name for the new measure
356
- * @returns A Calculated Measure instance
439
+ * @returns A calculated measure instance
357
440
  */
358
441
  export function yearToDateSum(measure, name) {
359
442
  return measureFunction(measure, name !== null && name !== void 0 ? name : 'YTD ' + measure.name, 'YTDSum');
360
443
  }
361
444
  /**
362
- * Calculates quarter to date (QTD) sum of the given measure.
363
- * Date dimension will be dynamically taken from the query.
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.
364
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
+ * ```
365
457
  * @param measure - Measure to apply the QTD Sum to
366
458
  * @param name - Name for the new measure
367
- * @returns A Calculated Measure instance
459
+ * @returns A calculated measure instance
368
460
  */
369
461
  export function quarterToDateSum(measure, name) {
370
462
  return measureFunction(measure, name !== null && name !== void 0 ? name : 'QTD ' + name, 'QTDSum');
371
463
  }
372
464
  /**
373
- * Calculates month to date (MTD) sum of the given measure.
374
- * Date dimension will be dynamically taken from the query.
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.
375
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
+ * ```
376
477
  * @param measure - Measure to apply the MTD Sum to
377
478
  * @param name - Name for the new measure
378
- * @returns A Calculated Measure instance
479
+ * @returns A calculated measure instance
379
480
  */
380
481
  export function monthToDateSum(measure, name) {
381
482
  return measureFunction(measure, name !== null && name !== void 0 ? name : 'MTD ' + measure.name, 'MTDSum');
382
483
  }
383
484
  /**
384
- * Calculates week to date (WTD) sum of the given measure.
385
- * Date dimension will be dynamically taken from the query.
485
+ * Creates a calculated measure that calculates the running total starting from the beginning
486
+ * of the week up to the current day.
386
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
+ * ```
387
497
  * @param measure - Measure to apply the WTD Sum to
388
498
  * @param name - Name for the new measure
389
- * @returns A Calculated Measure instance
499
+ * @returns A calculated measure instance
390
500
  */
391
501
  export function weekToDateSum(measure, name) {
392
502
  return measureFunction(measure, name !== null && name !== void 0 ? name : 'MTD ' + measure.name, 'WTDSum');
393
503
  }
394
504
  /**
395
- * Returns the running total of the measure by the defined dimension
396
- * according to the current sorting order in the query.
505
+ * Creates a calculated measure that calculates the running total of a given measure.
397
506
  *
398
- * By default, `RSUM` accumulates a measure by the sorting order of the dimension.
399
- * 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.
400
508
  *
401
- * Note: Filtering the `RSUM` column by Values,
402
- * filters the dimensions and recalculates the `RSUM` from the first filtered value.
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
+ * ```
403
514
  *
404
- * @param measure - Measure to apply the Running Sum to
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
405
526
  * @param _continuous - Boolean flag whether to accumulate the sum continuously
406
- * when there are two or more dimensions. The default value is False.
527
+ * when there are two or more dimensions. The default value is false.
407
528
  * @param name - Name for the new measure
408
- * @returns A Calculated Measure instance
529
+ * @returns A calculated measure instance
409
530
  */
410
531
  export function runningSum(measure, _continuous, name) {
411
532
  return measureFunction(measure, name !== null && name !== void 0 ? name : 'Running Sum ' + measure.name, 'RSum');
412
533
  }
413
534
  /**
414
- * Calculates growth over time. The time dimension to be used is determined by the time resolution in the query.
535
+ * Creates a calculated measure that calculates growth over a period of time.
415
536
  *
416
- * Formula: `(current value compared value) / compared value`.
537
+ * The time resolution is determined by the minimum date level of the date dimension in the query
538
+ * that uses the returned measure.
417
539
  *
418
- * @example
540
+ * Growth is calculated using the following formula: `(currentPeriod – previousPeriod) / previousPeriod`.
419
541
  *
420
- * If this month your value is 12, and last month it was 10, your Growth for this month is 20% (0.2).
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`).
421
544
  *
422
- * Calculation: `(12 10) / 10 = 0.2`
545
+ * If the previous period's value is greater than the current period, the growth will be negative.
423
546
  *
424
- * If this year your value is 80, and last year it was 100, your Growth for this year is -20% ( -0.2).
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`).
425
549
  *
426
- * Calculation: `(80 – 100) / 100 = -0.2`
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
+ * ```
427
556
  * @param measure - Measure to apply growth to
428
557
  * @param name - Name for the new measure
429
- * @returns A Calculated Measure instance
558
+ * @returns A calculated measure instance
430
559
  */
431
560
  export function growth(measure, name) {
432
561
  return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growth');
433
562
  }
434
563
  /**
435
- * Calculates growth rate over time. The time dimension to be used is determined by the time resolution in the query.
564
+ * Creates a calculated measure that calculates growth rate over a period of time.
436
565
  *
437
- * @example
438
- * If this month your value is 12, and last month it was 10, your Growth Rate for this month is 12/10 = 120% (1.2).
566
+ * The time resolution is determined by the minimum date level of the date dimension in the query
567
+ * that uses the returned measure.
439
568
  *
440
- * Calculation: `12 / 10 = 1.2`
569
+ * Growth rate is calculated using the following formula: `currentPeriod / previousPeriod`.
441
570
  *
442
- * If this year your value is 80, and last year it was 100, your Growth for this year is 80/100 = 80% ( 0.8).
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`).
443
573
  *
444
- * Calculation: `80 / 100 = 0.8`
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
+ * ```
445
585
  * @param measure - Measure to apply the Growth rate
446
586
  * @param name - Name for the new measure
447
- * @returns A Calculated Measure instance
587
+ * @returns A calculated measure instance
448
588
  */
449
589
  export function growthRate(measure, name) {
450
590
  return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growthrate');
451
591
  }
452
592
  /**
453
- * Calculates the growth from past week of the given measure.
454
- * 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.
455
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
+ * ```
456
613
  * @param measure - Measure to apply growth to
457
614
  * @param name - Name for the new measure
458
- * @returns A Calculated Measure instance
615
+ * @returns A calculated measure instance
459
616
  */
460
617
  export function growthPastWeek(measure, name) {
461
618
  return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growthpastweek');
462
619
  }
463
620
  /**
464
- * Calculates the growth from past month of the given measure.
465
- * Date dimension will be dynamically taken from the query
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.
466
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
+ * ```
467
641
  * @param measure - Measure to apply growth to
468
642
  * @param name - Name for the new measure
469
- * @returns A Calculated Measure instance
643
+ * @returns A calculated measure instance
470
644
  */
471
645
  export function growthPastMonth(measure, name) {
472
646
  return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growthpastmonth');
473
647
  }
474
648
  /**
475
- * Calculates the growth from past quarter of the given measure.
476
- * Date dimension will be dynamically taken from the query.
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`).
477
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
+ * ```
478
669
  * @param measure - Measure to apply growth to
479
670
  * @param name - Name for the new measure
480
- * @returns A Calculated Measure instance
671
+ * @returns A calculated measure instance
481
672
  */
482
673
  export function growthPastQuarter(measure, name) {
483
674
  return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growthpastquarter');
484
675
  }
485
676
  /**
486
- * Calculates the growth from past year of the given measure.
487
- * Date dimension will be dynamically taken from the query.
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.
488
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
+ * ```
489
697
  * @param measure - Measure to apply growth to
490
698
  * @param name - Name for the new measure
491
- * @returns A Calculated Measure instance
699
+ * @returns A calculated measure instance
492
700
  */
493
701
  export function growthPastYear(measure, name) {
494
702
  return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Growth', 'growthpastyear');
495
703
  }
496
704
  /**
497
- * Calculates the difference of the given measure.
498
- * Date dimension will be dynamically taken from the query.
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.
499
707
  *
500
- * @param measure - measure to apply difference to
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
501
718
  * @param name - Name for the new measure
502
- * @returns A Calculated Measure instance
719
+ * @returns A calculated measure instance
503
720
  */
504
721
  export function difference(measure, name) {
505
722
  return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Difference', 'diffpastperiod');
506
723
  }
507
724
  /**
508
- * Calculates the difference from past week of the given measure.
509
- * Ddate dimension will be dynamically taken from the query.
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.
510
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
+ * ```
511
736
  * @param measure - Measure to apply difference to
512
737
  * @param name - Name for the new measure
513
- * @returns A Calculated Measure instance
738
+ * @returns A calculated measure instance
514
739
  */
515
740
  export function diffPastWeek(measure, name) {
516
741
  return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Difference', 'diffpastweek');
517
742
  }
518
743
  /**
519
- * Calculates the difference from past month of the given measure.
520
- * Date dimension will be dynamically taken from the query.
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.
521
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
+ * ```
522
755
  * @param measure - Measure to apply difference to
523
756
  * @param name - Name for the new measure
524
- * @returns A Calculated Measure instance
757
+ * @returns A calculated measure instance
525
758
  */
526
759
  export function diffPastMonth(measure, name) {
527
760
  return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Difference', 'diffpastmonth');
528
761
  }
529
762
  /**
530
- * Calculates the difference from past quarter of the given measure.
531
- * Date dimension will be dynamically taken from the query.
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.
532
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
+ * ```
533
774
  * @param measure - Measure to apply difference to
534
775
  * @param name - Name for the new measure
535
- * @returns A Calculated Measure instance
776
+ * @returns A calculated measure instance
536
777
  */
537
778
  export function diffPastQuarter(measure, name) {
538
779
  return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Difference', 'diffpastquarter');
539
780
  }
540
781
  /**
541
- * Calculates the difference from past year of the given measure.
542
- * Date dimension will be dynamically taken from the query.
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.
543
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
+ * ```
544
793
  * @param measure - Measure to apply difference to
545
794
  * @param name - Name for the new measure
546
- * @returns A Calculated Measure instance
795
+ * @returns A calculated measure instance
547
796
  */
548
797
  export function diffPastYear(measure, name) {
549
798
  return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Difference', 'diffpastyear');
550
799
  }
551
800
  /**
552
- * Calculates the value of the past day of the given measure.
553
- * Date dimension will be dynamically taken from the query.
801
+ * Creates a calculated measure that calculates the value for the previous day.
554
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
+ * ```
555
808
  * @param measure - Measure to apply past value to
556
809
  * @param name - Name for the new measure
557
- * @returns A Calculated Measure instance
810
+ * @returns A calculated measure instance
558
811
  */
559
812
  export function pastDay(measure, name) {
560
813
  return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Past Day', 'pastday');
561
814
  }
562
815
  /**
563
- * Calculates the value of the past week of the given measure.
564
- * Date dimension will be dynamically taken from the query.
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.
565
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
+ * ```
566
826
  * @param measure - Measure to apply past value to
567
827
  * @param name - Name for the new measure
568
- * @returns A Calculated Measure instance
828
+ * @returns A calculated measure instance
569
829
  */
570
830
  export function pastWeek(measure, name) {
571
831
  return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Past Week', 'pastweek');
572
832
  }
573
833
  /**
574
- * Calculates the value of the path month of the given measure.
575
- * 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.
576
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
+ * ```
577
845
  * @param measure - Measure to apply past value to
578
846
  * @param name - Name for the new measure
579
- * @returns A Calculated Measure instance
847
+ * @returns A calculated measure instance
580
848
  */
581
849
  export function pastMonth(measure, name) {
582
850
  return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Past Month', 'pastmonth');
583
851
  }
584
852
  /**
585
- * Calculates the value of the past quarter of the given measure.
586
- * Date dimension will be dynamically taken from the query.
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.
587
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
+ * ```
588
864
  * @param measure - Measure to apply past value to
589
865
  * @param name - Name for the new measure
590
- * @returns A Calculated Measure instance
866
+ * @returns A calculated measure instance
591
867
  */
592
868
  export function pastQuarter(measure, name) {
593
869
  return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Past Quarter', 'pastquarter');
594
870
  }
595
871
  /**
596
- * Calculates the value of the past year of the given measure.
597
- * 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.
598
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
+ * ```
599
883
  * @param measure - Measure to apply past value to
600
884
  * @param name - Name for the new measure
601
- * @returns A Calculated Measure instance
885
+ * @returns A calculated measure instance
602
886
  */
603
887
  export function pastYear(measure, name) {
604
888
  return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Past Year', 'pastyear');
605
889
  }
606
890
  /**
607
- * Calculates contribution.
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`).
608
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 |
609
919
  * @param measure - Measure to apply the Contribution logic to
610
920
  * @param name - Name for the new measure
611
- * @returns A Calculated Measure instance
921
+ * @returns A calculated measure instance
612
922
  */
613
923
  export function contribution(measure, name) {
614
924
  return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Contribution', 'contribution');
615
925
  }
616
926
  /**
617
- * Fits a specified trend type to your measure. The trend types include linear,
618
- * logarithmic, advanced smoothing, and local estimates. It allows for an optional
619
- * feature to automatically identify and ignore anomalous values in the series.
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.
620
931
  *
621
932
  * Trend requires a Sisense instance version of L2023.6.0 or greater.
622
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
+ * ```
623
946
  * @param measure - Measure to apply the trend logic to
624
947
  * @param name - Name for the new measure
625
948
  * @param options - Trend options
626
- * @returns A Calculated Measure instance
949
+ * @returns A calculated measure instance
627
950
  */
628
951
  export function trend(measure, name, options) {
629
952
  let params;
@@ -638,24 +961,37 @@ export function trend(measure, name, options) {
638
961
  return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Trend', 'trend', params);
639
962
  }
640
963
  /**
641
- * Calculates Forecast leveraging advanced autoML techniques to generate
642
- * a forecast for a given measure.
964
+ * Creates a calculated measure that generates a forecast based on a specified measure employing
965
+ * advanced autoML techniques.
643
966
  *
644
- * This function offers flexibility with auto-selection of the best
645
- * statistical model or user-selected models, and it also provides control
646
- * over the time period used for training the model, as well as options to
647
- * 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.
648
971
  *
649
- * In addition to forecast, upper and lower confidence interval is returned
972
+ * In addition to the forecast, upper and lower confidence intervals are returned
650
973
  * with the name of the new measure and a suffix of _upper and _lower
651
974
  * respectively.
652
975
  *
653
976
  * Forecast requires a Sisense instance version of L2023.6.0 or greater.
654
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
+ * ```
655
991
  * @param measure - Measure to apply the forecast logic to
656
992
  * @param name - Name for the new measure
657
993
  * @param options - Forecast options
658
- * @returns A Calculated Measure instance
994
+ * @returns A calculated measure instance
659
995
  */
660
996
  export function forecast(measure, name, options) {
661
997
  let params;
@@ -682,19 +1018,53 @@ export function forecast(measure, name, options) {
682
1018
  return measureFunction(measure, name !== null && name !== void 0 ? name : measure.name + ' Forecast', 'forecast', params);
683
1019
  }
684
1020
  /**
685
- * Calculates the rank of a value in a list of values.
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.
686
1039
  *
687
1040
  * @example
688
- * `RANK(Total Cost, “ASC”, “1224”, Product, Years)`
689
- * will return the rank of the total annual cost per each product were sorted in ascending order.
690
- * @param measure - Measure to apply the Contribution logic to
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
691
1063
  * @param name - Name for the new measure
692
- * @param sort - By default sort order is descending.
693
- * @param rankType - By default the type is standard competition ranking `(“1224” ranking)`.
694
- * Supports also modified competition ranking `(“1334” ranking)`, dense ranking `(“1223” ranking)`,
695
- * and ordinal ranking `(“1234” ranking)`.
696
- * @param groupBy - Rank partitions attributes
697
- * @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
698
1068
  */
699
1069
  export function rank(measure, name, sort = RankingSortTypes.Descending, rankType = RankingTypes.StandardCompetition, groupBy = []) {
700
1070
  const builder = [];