diff --git a/content/v2.0/reference/flux/functions/built-in/transformations/aggregates/difference.md b/content/v2.0/reference/flux/functions/built-in/transformations/aggregates/difference.md index f864f6626..3e52efdba 100644 --- a/content/v2.0/reference/flux/functions/built-in/transformations/aggregates/difference.md +++ b/content/v2.0/reference/flux/functions/built-in/transformations/aggregates/difference.md @@ -17,7 +17,11 @@ _**Function type:** Aggregate_ _**Output data type:** Float_ ```js -difference(nonNegative: false, column: "_value") +difference( + nonNegative: false, + column: "_value", + keepFirst: false +) ``` ## Parameters @@ -34,6 +38,13 @@ Defaults to `"_value"`. _**Data type:** String_ +### keepFirst +Indicates the first row should be kept. +If `true`, the difference will be `null`. +Defaults to `false`. + +_**Data type:** Boolean_ + ## Subtraction rules for numeric types - The difference between two non-null values is their algebraic difference; or `null`, if the result is negative and `nonNegative: true`; @@ -90,6 +101,20 @@ from(bucket: "example-bucket") | 0004 | 6 | tv | | 0005 | null | tv | + +#### With keepFirst set to true +```js +|> difference(nonNegative: false, keepfirst: true): +``` +###### Output table +| _time | _value | tag | +|:-----:|:------:|:---:| +| 0001 | null | tv | +| 0002 | null | tv | +| 0003 | -2 | tv | +| 0004 | 6 | tv | +| 0005 | null | tv | +