query table for latest timestamp

Copper Contributor
let t =my_table
| summarize max(timestamp);
| where timestamp == t;

why doesn't this work?

I get

  'where' operator: Failed to resolve column or scalar expression named 't'

1 Reply


Hello Hanan, I think it works with a little change.


By default Kusto returns a set of data -  just like any other database. But you don't want to return a set, you are returning a single value like: " | where timestamp = datetime(2022-12-24)". This is why you need to use toscalar.


let  mytable =

datatable(timestamp:datetime) [






let t = mytable |  summarize max(timestamp);


| where timestamp == toscalar(t);



Or if you are NOT searching for a single value but the whole set, you would use the IN operator, not ==


| where timestamp  in (mytable);