Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Fungsi COUNT_DISTINCT menghitung jumlah item unik dalam kolom.
Sintaks
COUNT_DISTINCT( X )
Parameter
X - kolom atau ekspresi yang berisi item yang akan dihitung.
Cara kerja fungsi COUNT_DISTINCT
Fungsi COUNT_DISTINCT mengambil 1 parameter, yang dapat berupa nama metrik, dimensi, atau ekspresi dari jenis apa pun. COUNT_DISTINCT menampilkan total jumlah item unik dalam kolom atau ekspresi tersebut.
Untuk menghitung semua item, termasuk duplikat, gunakan COUNT.
Contoh
Example formula
Output
COUNT_DISTINCT(user_id)
22.854.921
COUNT_DISTINCT(order_id)
497.091.812
Batas COUNT_DISTINCT
Anda tidak dapat menerapkan fungsi ini ke kolom pra-agregasi ( jenis AgregasiOtomatis), atau ke ekspresi yang merupakan hasil dari fungsi agregasi lainnya. Misalnya, formula seperti COUNT_DISTINCT(Sessions) di sumber data Google Analytics akan menghasilkan error.
Untuk menghindari kemungkinan biaya kueri yang lebih tinggi saat menggunakan sumber data BigQuery, pertimbangkan untuk menggunakan APPROX_COUNT_DISTINCT.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 2025-07-30 UTC."],[],[],null,["# COUNT_DISTINCT\n\nThe `COUNT_DISTINCT` function counts the number of unique items in a field.\n\nSyntax\n------\n\n`COUNT_DISTINCT( `\u003cvar translate=\"no\"\u003eX\u003c/var\u003e` )`\n\n### Parameters\n\n- \u003cvar translate=\"no\"\u003eX\u003c/var\u003e - a field or expression that contains the items to be counted.\n\nHow the `COUNT_DISTINCT` function works\n---------------------------------------\n\nThe `COUNT_DISTINCT` function takes 1 parameter, which can be the name of a metric, dimension, or expression of any type. `COUNT_DISTINCT` returns the total number of unique items in that field or expression.\n\nTo count all items, including duplicates, use `COUNT`.\n| **Tip:** There are 2 other ways to apply this function:\n|\n| \u003cbr /\u003e\n|\n| - In a data source, change a field's **Aggregation** type to `Count Distinct`.\n| - in a report, [edit the field's aggregation](/looker/docs/studio/edit-fields-in-your-reports) in a chart.\n\nExamples\n--------\n\nLimits of `COUNT_DISTINCT`\n--------------------------\n\nYou can't apply this function to a pre-aggregated field ( **Aggregation** type of **Auto** ), or to an expression which is the result of another aggregation function. For example, a formula such as `COUNT_DISTINCT(Sessions)` in a Google Analytics data source will produce an error.\n\nTo avoid possibly incurring higher query costs when using BigQuery data sources, consider using `APPROX_COUNT_DISTINCT`.\n\nRelated resources\n-----------------\n\n- [Calculated fields](/looker/docs/studio/about-calculated-fields)\n- [Looker Studio function list](/looker/docs/studio/function-list)"]]