# Precision Threshold of Count in Canvas

**URL:** <https://discuss.elastic.co/t/precision-threshold-of-count-in-canvas/274664>\
**Category:** Kibana\
**Tags:** canvas\
**Created:** [June 1, 2021, 4:10pm UTC](https://discuss.elastic.co/t/precision-threshold-of-count-in-canvas/274664 "2021-06-01T16:10:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amy\_Collins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amy_collins/32/78031_2.png) [@Amy\_Collins](https://discuss.elastic.co/u/Amy_Collins)\
**Post date:** [June 1, 2021, 4:10pm UTC](https://discuss.elastic.co/t/precision-threshold-of-count-in-canvas/274664/1 "2021-06-01T16:10:56Z")

</div>

Hi,

Is there a way to set the precision threshold when performing a unique/distinct count using Canvas?

I need the count to be as accurate as possible. All hints and tips welcome.

---

<div class="post-metadata">

**Author:** ![poff](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/poff/32/81795_2.png) [@poff](https://discuss.elastic.co/u/poff)\
**Post date:** [June 1, 2021, 9:06pm UTC](https://discuss.elastic.co/t/precision-threshold-of-count-in-canvas/274664/2 "2021-06-01T21:06:32Z")

</div>

Hey there Amy,

This all depends on how you're doing your counting in the query or expression. Do you have an example query?

---

<div class="post-metadata">

**Author:** ![Amy\_Collins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amy_collins/32/78031_2.png) [@Amy\_Collins](https://discuss.elastic.co/u/Amy_Collins)\
**Post date:** [June 2, 2021, 8:14am UTC](https://discuss.elastic.co/t/precision-threshold-of-count-in-canvas/274664/3 "2021-06-02T08:14:15Z")

</div>

Hi poff,

Sure, I have been using the below:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/1/11de366b1736c45a38e725813971b022a45548bb.png)

However, it doesn't give me the expected value. I have also tried something like:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/9/8/98ba33093b5ac17fce5a7ef56cf7c8d29454da02.png)  
but this is even worse with a value much much less than expected.

I do get the correct value in a kibana visualization by using 'Unique Count' with the json input of `{"precision_threshold" : 40000}`

I have been reading this may have something to do with cardinality aggregation... do you think this is the reason here? if so, how to do I make the output more accurate?

---

<div class="post-metadata">

**Author:** ![poff](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/poff/32/81795_2.png) [@poff](https://discuss.elastic.co/u/poff)\
**Post date:** [June 2, 2021, 6:25pm UTC](https://discuss.elastic.co/t/precision-threshold-of-count-in-canvas/274664/4 "2021-06-02T18:25:19Z")

</div>

I just confirmed with the ES SQL team that aggregation like this is imprecise and unfortunately there isn't a way to tell the SQL endpoint to change the precision threshold. You might consider opening a ticket in the [elasticsearch github repo](https://github.com/elastic/elasticsearch) with this feature request for the SQL team.

As for the second example that uses the math function to count unique values, I'm a little surprised this isn't working. Are there any filters being passed in that would hide some expected data?

If all else fails and you were able to create a visualization outside of Canvas that pulls your data that you want, you can add that visualization directly to a workpad

---

<div class="post-metadata">

**Author:** ![Amy\_Collins](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amy_collins/32/78031_2.png) [@Amy\_Collins](https://discuss.elastic.co/u/Amy_Collins)\
**Post date:** [June 2, 2021, 7:12pm UTC](https://discuss.elastic.co/t/precision-threshold-of-count-in-canvas/274664/5 "2021-06-02T19:12:44Z")

</div>

Hi poff,

Thanks, I think I will have to open the ticket as this is very important to us.

As you can see below, the correct value is in the Kibana Visualization on the left. The top right is the output of the count(distinct uniqueIdentifier) and is over estimating by 61. The bottom right is the unique(uniqueIdentifier) and is vastly under estimating by 3991. No additional filters have been passed ☹  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/0/e050d05fc5a79e7b17282482d8cf4c00bc0ad8a0.png)

I don't really want to add the visualization to the workpad unless there is a way to sync the time range of the Visualizations with the Canvas Time Filter. Is this possible?

Thanks,  
Amy

---

<div class="post-metadata">

**Author:** ![poff](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/poff/32/81795_2.png) [@poff](https://discuss.elastic.co/u/poff)\
**Post date:** [June 3, 2021, 3:33pm UTC](https://discuss.elastic.co/t/precision-threshold-of-count-in-canvas/274664/6 "2021-06-03T15:33:10Z")

</div>

> I don't really want to add the visualization to the workpad unless there is a way to sync the time range of the Visualizations with the Canvas Time Filter. Is this possible?

Yes! You can do this two days:

1. Use a time filter on the workpad and pass in the `filters` function in the expression for the element. One note: you'll notice a default time range is specified for the visualization. If you want to control the data you're looking at via time filter on workpad, change the timerange on the visualization element to be a very large time range so then the range passed in by the time filter element is used
2. Use [Canvas workpad variables](https://www.elastic.co/guide/en/kibana/master/edit-workpads.html#create-variables) to define your start and end time for the range and use the variables in each expression, passing the variable in to the timerange argument

Also! I realized that the reason the number is so low (990) in that one element is because by default the essql function has a limit to the number of rows it will retrieve by default. You can change this by adding a `count` argument to the essql expression function call. Note: This might be not super performant since all the counting will happen in memory. Additionally, essql is capped at 10k records it can return at one time so if you have more than that, you might not get all your data

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 1, 2021, 3:33pm UTC](https://discuss.elastic.co/t/precision-threshold-of-count-in-canvas/274664/7 "2021-07-01T15:33:50Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
