# Custom chart: Histogram chart executed query SELECT DISTINCT

**URL:** <https://community.holistics.io/t/custom-chart-histogram-chart-executed-query-select-distinct/1262>\
**Category:** Report Bugs\
**Created:** [October 25, 2022, 3:56am UTC](https://community.holistics.io/t/custom-chart-histogram-chart-executed-query-select-distinct/1262 "2022-10-25T03:56:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Quang\_Ng](https://community.holistics.io/user_avatar/community.holistics.io/quang_ng/32/793_2.png) [@Quang\_Ng](https://community.holistics.io/u/Quang_Ng)\
**Post date:** [October 25, 2022, 3:56am UTC](https://community.holistics.io/t/custom-chart-histogram-chart-executed-query-select-distinct/1262/1 "2022-10-25T03:56:09Z")

</div>

I create a histogram chart as the example provided by holistic [here](https://github.com/holistics/custom-chart-library/blob/main/Common%20Charts/Histogram%20Chart/Sample%20code:%20Histogram%20Chart.md)

But the records count is not correct so I checked the executed query, and found out it uses `SELECT DISTINCT`. How can I use just `SELECT`?

```auto
#standardsql
SELECT DISTINCT
  `swaps_info`.`amount_out_usd` AS `frsp_aou_2f0bab`
FROM
  `data_warehouse`.`swaps_info_dev` `swaps_info`

```

---

<div class="post-metadata">

**Author:** ![tan](https://community.holistics.io/user_avatar/community.holistics.io/tan/32/358_2.png) [@tan](https://community.holistics.io/u/tan)\
**Post date:** [October 25, 2022, 11:02am UTC](https://community.holistics.io/t/custom-chart-histogram-chart-executed-query-select-distinct/1262/3 "2022-10-25T11:02:51Z")

</div>

Hi @Quang_Ng,

While we have the configuration to disable distinct (mentioned in a deleted response), that configuration is highly experimental (not apart of our documented public interface for aml) and after internal testing we find it not really usable since it mess with other other functionality that required distinct values (for example filter suggestion).

In your case, our advice is to change the Custom Chart to require a dimension and a measure instead:

- a dimension to define the data grain
- a measure to define the metric that you want to create the histogram on.

This set-up will work for your case while be more reusable. For example, if in your case you want the **Histogram of Total amount for each swap** then you would drag in the **swap\_id** dimension and the **Sum of amount\_usd**. Since this is more reusable, you can even change the dimension to **user\_id** to get the **Histogram of Total amount for each user**

Here is an example code for this Custom chart:

````auto
CustomChart {
  fields {
    field grain {
      type: 'dimension'
    }
    field metric {
      type: 'measure'
    }
  }
  template: @vgl
  {
    "data": {"values": @{values}},
    "transform": [
      {"bin": {"maxbins": 40}, "field": @{fields.metric.name}, "as": "binned_price"}
    ],
    "mark": {
      "type": "bar",
      "tooltip": true
    },
    "encoding": {
      "x": {"field": "binned_price", "type": "quantitative", "bin": {"binned": true, "step": 20}},
      "x2": {"field": "binned_price_end"},
      "y": {"aggregate": "count"}
    }
  }
  ;;
}```
````

---

<div class="post-metadata">

**Author:** ![Quang\_Ng](https://community.holistics.io/user_avatar/community.holistics.io/quang_ng/32/793_2.png) [@Quang\_Ng](https://community.holistics.io/u/Quang_Ng)\
**Post date:** [October 26, 2022, 3:57am UTC](https://community.holistics.io/t/custom-chart-histogram-chart-executed-query-select-distinct/1262/4 "2022-10-26T03:57:50Z")

</div>

Is there any hidden limit in the holistics executed query? (I have a total of more than 3M records)  
After I do as you told me, the query automatically applies `order by DESC` into the query. Then now, the small volumes are not shown in the dashboard anymore.

When I use the SQL editor to check, there are still lots of records that have volumes lower than 1:

 ![image](https://community.holistics.io/uploads/default/original/1X/f06791d0e9b0cc6188ab5a9803f8f8ad8b8e417d.jpeg)

---

<div class="post-metadata">

**Author:** ![vu.duong](https://community.holistics.io/user_avatar/community.holistics.io/vu.duong/32/483_2.png) [@vu.duong](https://community.holistics.io/u/vu.duong)\
**Post date:** [October 26, 2022, 12:14pm UTC](https://community.holistics.io/t/custom-chart-histogram-chart-executed-query-select-distinct/1262/5 "2022-10-26T12:14:48Z")

</div>

Hi @Quang_Ng  
This is indeed the expected result, since we have a hard limit of 1M records.  
Please refer to our doc here for more info: [Filtering & Limiting Data | Holistics Docs](https://docs.holistics.io/docs/filter-data#limiting-data)

I hope this is helpful.
