# DataTable

**URL:** https://discuss.elastic.co/t/datatable/196785
**Category:** Kibana
**Tags:** canvas
**Created:** [August 26, 2019, 1:56pm UTC](https://discuss.elastic.co/t/datatable/196785 "2019-08-26T13:56:57Z")
**Posts on this page:** 12
**Page:** 1

<div class="post-metadata">

### Author: ![wadhah](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wadhah](https://discuss.elastic.co/u/wadhah)
#### Post date: [August 26, 2019, 1:56pm UTC](https://discuss.elastic.co/t/datatable/196785/1 "2019-08-26T13:56:58Z")

</div>

Hello,

How Can I get this table :

 ![Capture2](https://us1.discourse-cdn.com/elastic/original/3X/0/3/032b6b1ff7ff311a5219f0af72e2e3a4b52cbbd7.png)

FROM:

 ![Capture](https://us1.discourse-cdn.com/elastic/original/3X/8/4/8461648205c1ea186ae9327b2546942d74454e0e.png)

---

<div class="post-metadata">

### Author: ![markov00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/markov00/32/33316_2.png) [@markov00](https://discuss.elastic.co/u/markov00)
#### Post date: [August 26, 2019, 2:10pm UTC](https://discuss.elastic.co/t/datatable/196785/2 "2019-08-26T14:10:20Z")

</div>

Hi @wadhah  
I think you can create a data table, specify Sum as metric aggregation on the count field.  
Then add a split row on Time (I'm not sure what is the time field format in that case, but I've build an example with a string field using terms agg). Then add another split row bucket on Category (terms aggregation)

 ![18](https://us1.discourse-cdn.com/elastic/original/3X/3/4/345e3f1f6dcc1fe42a92a8ba8f49bc4de7bc7d3c.png)

with this demo data set

```auto
PUT test_table/_doc/1
{
  "time": "Jul 19",
  "count": 1,
  "category": "A"
}

PUT test_table/_doc/2
{
  "time": "Jul 19",
  "count": 5,
  "category": "A"
}

PUT test_table/_doc/3
{
  "time": "Jul 19",
  "count": 2,
  "category": "B"
}

PUT test_table/_doc/4
{
  "time": "Aug 19",
  "count": 6,
  "category": "A"
}

PUT test_table/_doc/4
{
  "time": "Aug 19",
  "count": 6,
  "category": "A"
}

PUT test_table/_doc/5
{
  "time": "Aug 19",
  "count": 3,
  "category": "B"
}

PUT test_table/_doc/6
{
  "time": "Aug 19",
  "count": 1,
  "category": "B"
}

```

---

<div class="post-metadata">

### Author: ![markov00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/markov00/32/33316_2.png) [@markov00](https://discuss.elastic.co/u/markov00)
#### Post date: [August 26, 2019, 2:11pm UTC](https://discuss.elastic.co/t/datatable/196785/3 "2019-08-26T14:11:09Z")

</div>

oh, maybe I miss understand the question, was that related to build the table in Canvas?

---

<div class="post-metadata">

### Author: ![wadhah](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wadhah](https://discuss.elastic.co/u/wadhah)
#### Post date: [August 26, 2019, 2:16pm UTC](https://discuss.elastic.co/t/datatable/196785/4 "2019-08-26T14:16:38Z")

</div>

Thank you @markov00 for the quick update.  
Yap I am trying to build in Canvas

---

<div class="post-metadata">

### Author: ![wadhah](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wadhah](https://discuss.elastic.co/u/wadhah)
#### Post date: [August 26, 2019, 2:18pm UTC](https://discuss.elastic.co/t/datatable/196785/5 "2019-08-26T14:18:29Z")

</div>

And concerning the date I am depending on "timestamp" And I used "mapColumn "time" expression={getCell "time" | formatdate format="MMM YYYY"}" to get in that way

---

<div class="post-metadata">

### Author: ![wadhah](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wadhah](https://discuss.elastic.co/u/wadhah)
#### Post date: [August 28, 2019, 8:06am UTC](https://discuss.elastic.co/t/datatable/196785/6 "2019-08-28T08:06:35Z")

</div>

@markov00 Hello again ... I was wondering if there are any updates concerning this topic.  
Thank you in advance

---

<div class="post-metadata">

### Author: ![markov00](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/markov00/32/33316_2.png) [@markov00](https://discuss.elastic.co/u/markov00)
#### Post date: [August 28, 2019, 3:04pm UTC](https://discuss.elastic.co/t/datatable/196785/7 "2019-08-28T15:04:02Z")

</div>

@Catherine_Liu can you help us here?

---

<div class="post-metadata">

### Author: ![Catherine\_Liu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/catherine_liu/32/34294_2.png) [@Catherine\_Liu](https://discuss.elastic.co/u/Catherine_Liu)
#### Post date: [August 28, 2019, 4:34pm UTC](https://discuss.elastic.co/t/datatable/196785/8 "2019-08-28T16:34:31Z")

</div>

@wadhah The table will display the column names as the table headers. You can style these table headers with CSS to capitalize your column names like this:

 ![50%20AM](https://us1.discourse-cdn.com/elastic/original/3X/e/4/e44a464e5f5bb1ef4778fa259126c882f2752345.png)

If you need more than just a simple text transform, you can rename your columns using [`alterColumn`](https://www.elastic.co/guide/en/kibana/current/canvas-function-reference.html#alterColumn_fn) to display the header you desire.

Here's an example expression:

 ![23%20AM](https://us1.discourse-cdn.com/elastic/original/3X/0/7/073706b05e6c5d65888d1ee83f55455ad3fe5642.png)

```auto
filters
| esdocs index="cluster_ONE:kibana_sample_data_ecommerce" fields="taxful_total_price, user, order_date"
| alterColumn "order_date" name="Date Ordered"
| table
| render

```

Note: if you change the name using `alterColumn`, you'll need to also update any references to this column with the new name in a math expression or plot configuration.

---

<div class="post-metadata">

### Author: ![wadhah](https://avatars.discourse-cdn.com/v4/letter/w/bc8723/32.png) [@wadhah](https://discuss.elastic.co/u/wadhah)
#### Post date: [August 28, 2019, 5:51pm UTC](https://discuss.elastic.co/t/datatable/196785/9 "2019-08-28T17:51:22Z")

</div>

Hello @markov00 and @Catherine_Liu : Thank you so much for the update. However, I think I was not clear about the real issue : In fact I am not looking forward to change "category" to "Category".  
So, I have an index which includes : "time", "category" among its fields . And I am trying to build a table as shown in the first picture

 ![Capture2](https://us1.discourse-cdn.com/elastic/original/3X/0/3/032b6b1ff7ff311a5219f0af72e2e3a4b52cbbd7.png)

But I am getting this table:

 ![Capture](https://us1.discourse-cdn.com/elastic/original/3X/8/4/8461648205c1ea186ae9327b2546942d74454e0e.png)

I am using these commands:

```
       "SELECT category, COUNT(category) AS Count, \"@timestamp\" AS Time
        FROM "index"
        GROUP BY Time, category
        ORDER BY Time ASC"

```

And in the expression editor I changed the date to the format "MMM YYYY"  
Ps: If I get rid of "time" or "category" from the "GROUP BY" section I get an error.

Thank you for your cooperation in advance

---

<div class="post-metadata">

### Author: ![Catherine\_Liu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/catherine_liu/32/34294_2.png) [@Catherine\_Liu](https://discuss.elastic.co/u/Catherine_Liu)
#### Post date: [August 28, 2019, 8:49pm UTC](https://discuss.elastic.co/t/datatable/196785/10 "2019-08-28T20:49:05Z")

</div>

Ah sorry, I misunderstood the issue.

You can use the `ply` function to handle the grouping and aggregation.

Here's an example using the Ecommerce sample data set:

![59%20PM](https://us1.discourse-cdn.com/elastic/original/3X/f/6/f6272e39338a3ad688d612f5e327acbeca84b65d.png)

```auto
filters
| essql 
  query="SELECT timestamp, Carrier, count(*) as number_of_flights FROM \"kibana_sample_data_flights\" GROUP BY Carrier, timestamp"
  count=10000
| mapColumn "timestamp" fn={getCell "timestamp" | formatdate "MMM YYYY"}
| ply by="timestamp" by="Carrier" fn={math "sum(number_of_flights)"}
| table
| render

```

The `ply` function here splits up the data into unique sub-datatables per combination of month/year `timestamp` and `Carrier` and calculates the sum of the `number_of_flights` in each sub-datatable. Then it merges the results back into a single datatable with one row per result.

---

<div class="post-metadata">

### Author: ![Catherine\_Liu](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/catherine_liu/32/34294_2.png) [@Catherine\_Liu](https://discuss.elastic.co/u/Catherine_Liu)
#### Post date: [August 29, 2019, 12:03am UTC](https://discuss.elastic.co/t/datatable/196785/11 "2019-08-29T00:03:30Z")

</div>

An alternative is to have Elasticsearch handle rounding the date to the month using the [`HISTOGRAM`](https://www.elastic.co/guide/en/elasticsearch/reference/current/sql-functions-grouping.html#sql-functions-grouping-histogram) aggregation, which results in a faster query and possibly more accurate one since the aggregation isn't limited to aggregation only the first 10000 documents like in the expression above. Here's the same example above with a different SQL query with slightly different results:

 ![19%20PM](https://us1.discourse-cdn.com/elastic/original/3X/6/9/69fc2f03c4bda3d0f2f5e9f125b3ad42522e899a.png)

```auto
filters
| essql 
  query="SELECT HISTOGRAM(timestamp, INTERVAL 1 MONTH) as month, Carrier, count(*) as number_of_flights FROM \"kibana_sample_data_flights\" GROUP BY Carrier,month" count=10000
| table
| render

```

---

<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: [September 26, 2019, 12:03am UTC](https://discuss.elastic.co/t/datatable/196785/12 "2019-09-26T00:03:35Z")

</div>

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