Forum Discussion
Summarize dynamic array?
Hi, I apologize for my lack of experience, however this is literally my first time using / learning about Azure Data Explorer.
I have this data:
| project Data1 = Data[0], Data2 = Data[1], Data3 = Data[2]
where Data is in the form of an integer array: (something like [9, 12, 24])
I want to summarize the data to produce an output with the most common number for each index, so if Data was:
[9, 12, 24]
[17, 12, 37]
[9, 17, 37]
Then the output of the function would be:
Data1 | 9 |
Data2 | 12 |
Data3 | 37 |
Is this possible? Thanks!
8 Replies
- Yoni
Microsoft
Here's one option:
datatable(Data:dynamic) [ dynamic([9, 12, 24]), dynamic([17, 12, 37]), dynamic([9, 17, 37]), ] | mv-expand with_itemindex = ArrayIndex Data to typeof(int) | summarize c = count() by Data, ArrayIndex | summarize arg_max(c, Data) by ArrayIndex | project-away c
- bphillips09Copper Contributor
Yoni Thanks for the reply! However, these sets aren't pre-programmed sets, i.e. would it be possible to create a datatable like this?:
datatable(Data:dynamic) [ dynamic([Data1, Data2, Data3]) ]
Where Data1, Data2, and Data3 are three distinct variables that change?
- Yoni
Microsoft
using the `datatable` operator in that sample was just in order to have some input data set. the "point" (answer to your original question) was in the lines starting from `| mv-expand ...`
if that doesn't solve your issue -perhaps, you can show a sample of how your _real_ data looks like, so that we can work with that?