How to aggregate sum all the columns in Kusto?

For the following datatable, is there a way to get the expected result without having to specify all the columns one by one? the problem here is that my real table has 20+ columns. I am looking for a cleaner solution.

Expected Result

Col1Sum | Col2Sum | Col3Sum | Col4Sum
--------------------------------------
3       | 3       | 3       | 3

Table + Query

datatable(Col1: int, Col2: int, Col3: int, Col4: int)
[
  1, 1, 1, 1,
  1, 1, 1, 1,
  1, 1, 1, 1,
]
| summarize
  Col1Sum = sum(Col1),
  Col2Sum = sum(Col2),
  Col3Sum = sum(Col3),
  Col4Sum = sum(Col4);

Upvotes: 0

Views: 1912

Answers (1)

yifats
yifats

Reputation: 2744

You can generate the query using a Kusto query:

datatable(Col1: int, Col2: int, Col3: int, Col4: int)
[
  1, 1, 1, 1,
  1, 1, 1, 1,
  1, 1, 1, 1,
]
| getschema 
| extend SumColumn = strcat(ColumnName,  "Sum = sum(", ColumnName, ") ")
| summarize replace('"|\\[|]', "", tostring(make_list(SumColumn)))
| project Query = strcat("summarize ", Column1)

enter image description here

Upvotes: 3

Related Questions