Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
APPROX_COUNT_DISTINCT
A função APPROX_COUNT_DISTINCT contabiliza o número aproximado de itens exclusivos em um campo.
Sintaxe
APPROX_COUNT_DISTINCT(X)
Parâmetros
field_expression: campo ou expressão que contém os itens a serem contabilizados.
Sobre a função APPROX_COUNT_DISTINCT
A função APPROX_COUNT_DISTINCT usa um parâmetro, que pode ser o nome de uma métrica, dimensão ou expressão de qualquer tipo. A APPROX_COUNT_DISTINCT retorna o número aproximado de itens exclusivos nesse campo ou expressão.
APPROX_COUNT_DISTINCT é mais eficiente no processamento de consultas do que COUNT_DISTINCT, mas retorna resultados menos exatos. Caso seu conjunto de dados seja muito grande ou a performance do relatório seja mais importante do que contagens exatas, use APPROX_COUNT_DISTINCT. Usar APPROX_COUNT_DISTINCT em vez de COUNT_DISTINCT também pode ajudar a reduzir os custos de consulta em fontes de dados do BigQuery.
Para uma explicação detalhada de como funciona a agregação aproximada, consulte a documentação do BigQuery.
Exemplo
APPROX_COUNT_DISTINCT(Page): contabiliza o número aproximado de valores únicos na dimensão Página.
Limites de APPROX_COUNT_DISTINCT
A função APPROX_COUNT_DISTINCT só fica disponível quando usada com fontes de dados do BigQuery.
No caso de fontes de dados que não são compatíveis com APPROX_COUNT_DISTINCT, APPROX_COUNT_DISTINCT vai funcionar como COUNT_DISTINCT.
Não é possível aplicar essa função a uma métrica pré-agregada ( tipo de agregaçãoAuto) ou a uma expressão resultante de outra função de agregação. Por exemplo, uma fórmula como APPROX_COUNT_DISTINCT(Sessions) em uma fonte de dados do Google Analytics vai gerar um erro.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-08-25 UTC."],[],[],null,["APPROX_COUNT_DISTINCT\n=====================\n\nThe `APPROX_COUNT_DISTINCT` function counts the approximate number of unique items in a field.\n| **Note:** `APPROX_COUNT_DISTINCT` is available only when your data comes from a BigQuery data source. For other data source types, use `COUNT_DISTINCT`.\n\nSyntax\n------\n\n`APPROX_COUNT_DISTINCT(`\u003cvar translate=\"no\"\u003eX\u003c/var\u003e`)`\n\n### Parameters\n\n- \u003cvar translate=\"no\"\u003efield_expression\u003c/var\u003e - a field or expression that contains the items to be counted.\n\nHow the `APPROX_COUNT_DISTINCT` function works\n----------------------------------------------\n\nThe `APPROX_COUNT_DISTINCT` function takes one parameter, which can be the name of a metric, dimension, or expression of any type. `APPROX_COUNT_DISTINCT` returns the approximate number of unique items in that field or expression.\n\n`APPROX_COUNT_DISTINCT` is more efficient in terms of query processing than `COUNT_DISTINCT`, but returns less exact results. If your dataset is very large, or if the performance of your report is more important than exact counts, consider using `APPROX_COUNT_DISTINCT`. Using `APPROX_COUNT_DISTINCT` instead of `COUNT_DISTINCT` can also help reduce query costs when using BigQuery data sources.\n\nFor an in-depth explanation of how approximate aggregation works, see the [BigQuery documentation](/bigquery/docs/reference/standard-sql/approximate_aggregate_functions).\n\nExample\n-------\n\n\u003e `APPROX_COUNT_DISTINCT(`\u003cvar translate=\"no\"\u003ePage\u003c/var\u003e`)` - counts the approximate number of unique values in the **Page** dimension.\n\nLimits of `APPROX_COUNT_DISTINCT`\n---------------------------------\n\n- The `APPROX_COUNT_DISTINCT` function is available only when used with BigQuery data sources.\n\n- For data sources which don't support `APPROX_COUNT_DISTINCT`, `APPROX_COUNT_DISTINCT` will act like `COUNT_DISTINCT`.\n\n- You can't apply this function to a pre-aggregated metric ( **Aggregation** type of **Auto** ), or to an expression that is the result of another aggregation function. For example, a formula such as `APPROX_COUNT_DISTINCT(Sessions)` in a Google Analytics data source will produce an error.\n\nRelated resources\n-----------------\n\n- [Calculated fields](/looker/docs/studio/about-calculated-fields)\n- [Looker Studio function list](/looker/docs/studio/function-list)"]]