You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/user/ppl/cmd/addcoltotals.md
+53-43Lines changed: 53 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,76 +24,86 @@ The `addcoltotals` command supports the following parameters.
24
24
|`labelfield`| Optional | The field in which the label is placed. If the field does not exist, it is created and the label is shown in the summary row (last row) of the new field. |
25
25
|`label`| Optional | The text that appears in the summary row (last row) to identify the computed totals. When used with `labelfield`, this text is placed in the specified field in the summary row. Default is `Total`. |
26
26
27
-
## Example 1: Basic example
27
+
## Example 1: Adding column totals to a severity breakdown
28
28
29
-
The following query places the label in an existing field:
29
+
The following query adds a total row to a severity breakdown, showing the grand total of all log entries:
30
30
31
31
```ppl
32
-
source=accounts
33
-
| fields firstname, balance
34
-
| head 3
35
-
| addcoltotals labelfield='firstname'
32
+
source=otellogs
33
+
| stats count() as log_count by severityText
34
+
| sort severityText
35
+
| fields severityText, log_count
36
+
| addcoltotals labelfield='severityText'
36
37
```
37
38
38
39
The query returns the following results:
39
40
40
41
```text
41
-
fetched rows / total rows = 4/4
42
-
+-----------+---------+
43
-
| firstname | balance |
44
-
|-----------+---------|
45
-
| Amber | 39225 |
46
-
| Hattie | 5686 |
47
-
| Nanette | 32838 |
48
-
| Total | 77749 |
49
-
+-----------+---------+
42
+
fetched rows / total rows = 5/5
43
+
+--------------+-----------+
44
+
| severityText | log_count |
45
+
|--------------+-----------|
46
+
| DEBUG | 3 |
47
+
| ERROR | 7 |
48
+
| INFO | 6 |
49
+
| WARN | 4 |
50
+
| Total | 20 |
51
+
+--------------+-----------+
50
52
```
51
53
52
-
## Example 2: Adding column totals with a custom summary label
54
+
## Example 2: Adding column totals with a custom label
53
55
54
-
The following query adds totals after a `stats` command where the final summary event label is `Sum`. It also creates a new field specified by `labelfield` because this field does not exist in the data:
56
+
The following query adds totals to error counts per service with a custom summary label:
The following query uses the `addcoltotals` command with all options set:
84
+
The following query uses the `addcoltotals` command with all options set, totaling only the specified numeric fields and placing the summary label in a new column:
78
85
79
86
```ppl
80
-
source=accounts
81
-
| where age > 30
82
-
| stats avg(balance) as avg_balance, count() as count by state
Copy file name to clipboardExpand all lines: docs/user/ppl/cmd/addtotals.md
+58-70Lines changed: 58 additions & 70 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,103 +27,91 @@ The `addtotals` command supports the following parameters.
27
27
|`label`| Optional | The text that appears in the summary row (last row) to identify the computed totals. When used with `labelfield`, this text is placed in the specified field in the summary row. Default is `Total`. Applicable when `col=true`. This parameter has no effect when the `labelfield` and `fieldname` parameters specify the same field name. |
28
28
|`fieldname`| Optional | The field used to store row totals. Applicable when `row=true`. |
29
29
30
-
## Example 1: Basic example
30
+
## Example 1: Adding column totals
31
31
32
-
The following query places the label in an existing field:
32
+
The following query counts errors and warnings per service, then adds a column total row showing the grand totals:
## Example 2: Adding column totals with a custom summary label
56
-
57
-
The following query adds totals after a `stats` command, with the final summary event labeled `Sum`. It also creates a new field specified by `labelfield` because the field does not exist in the data:
58
-
59
-
60
-
```ppl
61
-
source=accounts
62
-
| fields account_number, firstname , balance , age
If you set `row=true` in the preceding example, both row totals and column totals try to use the same field name (`Total`), creating a conflict. When this happens, the summary row label displays as `null` instead of `Sum` because the field becomes numeric (for row totals) and cannot display string values:
60
+
## Example 2: Adding row totals
82
61
62
+
The following query counts errors and warnings separately per service, then adds a row total showing the combined count of actionable issues per service:
83
63
84
64
```ppl
85
-
source=accounts
86
-
| fields account_number, firstname , balance , age
0 commit comments