title: Aggregate contents of array column in Azure Data Explorer
body: <p>I have some data stored in the customEvents property bag that I want to perform aggregation and analytics on. I'm new to the analytics queries that you can run against AppInsights using the Azure Data Explorer query language and am stuck.</p>
  
  <p>I have a handle on converting the contents of one of the property bag's key-value-pairs into an array of numbers (in the example below, that output is represented by <code>items</code>. </p>
  
  <pre><code>let items = parse_json('{"operation_Id": "12345Z12", "days":[43, 21, 65]}');
  print items.operation_Id, items.days;
  </code></pre>
  
  <p>However, when I need to calculate the average value of the items in the array for each operation_Id, I run into a documentation wall. I've looked at <code>mvexpand</code>, <code>let</code> (using a lambda expression), <code>datatable</code>, using dynamic data types, etc. The blocking issue I've had with using <code>mvexpand</code> is that I want to associate every row in the output correlated with its operation <code>operation_Id</code>, and <code>mvexpand</code> only seems to persist that relationship in the first row. With a <code>datatable</code>, the type doesn't support a pipeline input.</p>
  
  <p>Another common error I've (including from the code sample below is <strong>Operator Source Expression should be table or column</strong>).</p>
  
  <pre><code>let items = parse_json('{"days":[43, 21, 65]}');
  
  let arraySum = (T:(x: long))
  {
     T 
     | summarize sum(x) 
  };
  items
  | project days | invoke arraySum()
  </code></pre>
  
  <p>If necessary, I can perform the aggregation code in JavaScript and only pass the calculated average in the property bag, but it feels like a waste to throw away the raw data values. Is there some obvious calculation or aggregation function that solves this problem? </p>