What's new from Grafana Labsbreadcrumb arrow Estimate distinct log values with approx_count_distinct
What's new from Grafana Labs
What's new from Grafana Labs
Grafana Cloud Generally Available Open Source Enterprise Generally Available Logs
Release date
2026-09-29
Self-managed release
loki-v4.0.0

Estimate distinct log values with approx_count_distinct

Estimate how many distinct values appear in your logs when an exact count would create too many series.

count by (<field>) returns one series for every distinct value. For a field such as a user ID, IP address, or session token, that series count can hit Loki’s maximum series limit or time out the query. approx_count_distinct estimates the number of distinct values of a label or extracted field and returns one series per group.

logql
approx_count_distinct(
  user_id,
  {job="webapp"} | json [1d]
)
logql
approx_count_distinct(
  ip_address,
  {job="api"} | json [1d]
) by (version)

Related What's new posts