# Create Datatable with multiple queries

**URL:** <https://discuss.elastic.co/t/create-datatable-with-multiple-queries/272387>\
**Category:** Kibana\
**Tags:** canvas\
**Created:** [May 7, 2021, 8:23am UTC](https://discuss.elastic.co/t/create-datatable-with-multiple-queries/272387 "2021-05-07T08:23:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![NightWalker](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nightwalker/32/81992_2.png) [@NightWalker](https://discuss.elastic.co/u/NightWalker)\
**Post date:** [May 7, 2021, 8:23am UTC](https://discuss.elastic.co/t/create-datatable-with-multiple-queries/272387/1 "2021-05-07T08:23:57Z")

</div>

Hello,

I want to create a datatable from multiple queries where each of them have a different WHERE Clause. Each query should be shown as a new column which are grouped by a daily histogram.

I’m pretty sure that it should be something like this but in the example below the col2 and col3 tables are getting the value "null". Is something like this possible?

```auto
	filters 
	| essql 
	  query="SELECT SUM(number_of_items) as item_count FROM \"db_billing_*\" WHERE customerGroup ='mycustomer' AND error_code=0 GROUP BY HISTOGRAM(\"@timestamp\", INTERVAL 1 DAY) ORDER BY HISTOGRAM(\"@timestamp\", INTERVAL 1 DAY) DESC"
	| mapColumn name="col2" fn={filters |essql query="SELECT COUNT(id) as myCount FROM \"db_billing_*\" WHERE customerGroup ='mycustomer' AND error_code=0 AND customerID<1000 GROUP BY HISTOGRAM(\"@timestamp\", INTERVAL 1 DAY) ORDER BY HISTOGRAM(\"@timestamp\", INTERVAL 1 DAY) DESC"}
	| mapColumn name="col3" fn={filters |essql query="SELECT COUNT(UNIQUE(customerID)) as myCount2 FROM \"db_billing_*\" WHERE customerGroup ='mycustomer' AND error_code=0 AND location<>'test' GROUP BY HISTOGRAM(\"@timestamp\", INTERVAL 1 DAY) ORDER BY HISTOGRAM(\"@timestamp\", INTERVAL 1 DAY) DESC"}
	| table 
	| render

```

---

<div class="post-metadata">

**Author:** ![brianseeders](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/brianseeders/32/84831_2.png) [@brianseeders](https://discuss.elastic.co/u/brianseeders)\
**Post date:** [May 13, 2021, 4:17pm UTC](https://discuss.elastic.co/t/create-datatable-with-multiple-queries/272387/2 "2021-05-13T16:17:36Z")

</div>

Hello, @NightWalker,

mapColumn calculates a value using the data in the other cells in the same row, which I think is why you're getting `null`.

I think that you essentially need SQL `UNION` functionality to achieve what you need, which unfortunately is not currently supported. See related GitHub issue here: [Elasticsearch SQL Support for UNIONs · Issue #34414 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/issues/34414)

It may be worth chiming in with your use case.

Thanks,  
Brian

---

<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:** [June 10, 2021, 4:18pm UTC](https://discuss.elastic.co/t/create-datatable-with-multiple-queries/272387/3 "2021-06-10T16:18:02Z")

</div>

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