Hello @Galgani, Stefano ,
it's hard to optimes a table out of the blue.
It's not clear neither how many records there are in the table, how large your cluster is, nor how much of the data is available in the cache.
Any KQL query acts like a funnel so I would put the largest filter at the top.
You say you need to find the last ServerTimeStamp of a specific TimeseriesId so I would leave out the TimeSeriesName part.
the arg_max seems to be able to find the latest date already:
Telemetry | summarize arg_max(ServerTimeStamp, *) by TimeseriesId | where TimeseriesId == '1d4037bc-xxxx-xxxx-xxxx-xxxxxxxxx' | project TimeseriesId, TimeseriesName, ServerTimeStamp, ServerTimeStampString = todatetime(unixtime_seconds_todatetime(ServerTimeStamp)), Value, Quality
Does this help?
Otherwise, an alternative is this top 1 by solution:
Telemetry | order by ServerTimeStamp desc | where TimeseriesId == '1d4037bc-xxxx-xxxx-xxxx-xxxxxxxxx' | top 1 by TimeseriesId
Try to find out which part is slowing you down by 'pealing off' statements of your query.
This answer is written by myself, not by some AI. If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.