I’m working with Kusto Query Language (KQL) and I want to reference a list of columns in one variable for summarization, instead of specifying each column individually. Here’s an example of what I have:
<code>let data = datatable(Category: string, Category2: string)
[
'A', 'X',
'A', 'X',
'A', 'X',
'B', 'Y',
'B', 'Y',
'B', 'Y',
'B', 'Y',
'C', 'Z',
'C', 'Z',
'C', 'Z',
'C', 'Z',
'C', 'T'
];
data
| summarize count() by Category, Category2
</code>
<code>let data = datatable(Category: string, Category2: string)
[
'A', 'X',
'A', 'X',
'A', 'X',
'B', 'Y',
'B', 'Y',
'B', 'Y',
'B', 'Y',
'C', 'Z',
'C', 'Z',
'C', 'Z',
'C', 'Z',
'C', 'T'
];
data
| summarize count() by Category, Category2
</code>
let data = datatable(Category: string, Category2: string)
[
'A', 'X',
'A', 'X',
'A', 'X',
'B', 'Y',
'B', 'Y',
'B', 'Y',
'B', 'Y',
'C', 'Z',
'C', 'Z',
'C', 'Z',
'C', 'Z',
'C', 'T'
];
data
| summarize count() by Category, Category2
I want to achieve the same result by referencing the columns from a variable, something like this:
<code>let data = datatable(Category: string, Category2: string)
[
'A', 'X',
'A', 'X',
'A', 'X',
'B', 'Y',
'B', 'Y',
'B', 'Y',
'B', 'Y',
'C', 'Z',
'C', 'Z',
'C', 'Z',
'C', 'Z',
'C', 'T'
];
let columns = pack_array('Category', 'Category2');
data
| summarize count() by columns
</code>
<code>let data = datatable(Category: string, Category2: string)
[
'A', 'X',
'A', 'X',
'A', 'X',
'B', 'Y',
'B', 'Y',
'B', 'Y',
'B', 'Y',
'C', 'Z',
'C', 'Z',
'C', 'Z',
'C', 'Z',
'C', 'T'
];
let columns = pack_array('Category', 'Category2');
data
| summarize count() by columns
</code>
let data = datatable(Category: string, Category2: string)
[
'A', 'X',
'A', 'X',
'A', 'X',
'B', 'Y',
'B', 'Y',
'B', 'Y',
'B', 'Y',
'C', 'Z',
'C', 'Z',
'C', 'Z',
'C', 'Z',
'C', 'T'
];
let columns = pack_array('Category', 'Category2');
data
| summarize count() by columns
However, I get the following error:
<code>Summarize group key '' is of a 'dynamic' type. Please use an explicit cast (for example, 'summarize ... by tostring()') as grouping by a 'dynamic' type is not supported.
</code>
<code>Summarize group key '' is of a 'dynamic' type. Please use an explicit cast (for example, 'summarize ... by tostring()') as grouping by a 'dynamic' type is not supported.
</code>
Summarize group key '' is of a 'dynamic' type. Please use an explicit cast (for example, 'summarize ... by tostring()') as grouping by a 'dynamic' type is not supported.
Is there a way to achieve this in KQL, or do I need to specify each column individually? Any help or alternative approaches would be greatly appreciated!