Rene
Rene

Reputation: 1204

How to access multiple kusto let statement results in a consecutive query?

I'd like to query the input value for the bin() function prior to the execution, in which the three dots (...) represent a integer variable:

let bin_size = 
T 
| project X, Y
| summarize y_bin_size=(max(Y) - min(Y)) / ..., x_bin_size=(max(X) - min(X)) / ...;
let result = 
T
| project X, Y
| summarize Count=count() by bin(X, bin_size.x_bin_size), bin(Y, bin_size.y_bin_size);
result

In ADX the bin_size is shown by hovering over the variable, as shown in the image:

enter image description here

Therefore, I suppose, I could access the variables y_bin_size and x_bin_size for my final query.

How can I access the inner results of the first let query? Can I combine this in one query?

Thanks a lot.

Upvotes: 1

Views: 786

Answers (1)

Yoni L.
Yoni L.

Reputation: 25895

you could try something like this:

  1. in the first part of the query: calculate and store the bin sizes in a scalar property bag of type dynamic.
  2. access the properties (x and y) from the bag in #1 in the other part of your query.
let bin_sizes = toscalar(
    T
    | summarize bag_pack("y", (max(Y) - min(Y)) / 5,
                         "x", (max(X) - min(X)) / 6)
)
;
let result = 
    T
    | summarize Count=count() by
          bin(X, todouble(bin_sizes.x)),
          bin(Y, todouble(bin_sizes.y))
;
result
``

Upvotes: 1

Related Questions