# Getting error \_.%x is not a function

**URL:** <https://discuss.elastic.co/t/getting-error-x-is-not-a-function/255702>\
**Category:** Kibana\
**Created:** [November 17, 2020, 1:00pm UTC](https://discuss.elastic.co/t/getting-error-x-is-not-a-function/255702 "2020-11-17T13:00:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sam7](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@sam7](https://discuss.elastic.co/u/sam7)\
**Post date:** [November 17, 2020, 1:00pm UTC](https://discuss.elastic.co/t/getting-error-x-is-not-a-function/255702/1 "2020-11-17T13:00:20Z")

</div>

Trying to get the count of products from my json index (eg. test-index). Aggregation output from dev tool is mentioned below.

{  
"took" : 0,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 1,  
"successful" : 1,  
"skipped" : 0,  
"failed" : 0  
},  
"hits" : {  
"total" : {  
"value" : 762,  
"relation" : "eq"  
},  
"max\_score" : null,  
"hits" :   
},  
"aggregations" : {  
"types\_count" : {  
"value" : 760  
}  
}  
}

#########Vega Code used

```auto
{ 
"$schema": "https://vega.github.io/schema/vega/v5.json",
"data": [ 
    { 
    "name": "table",
     url: { 
        %context%: true
        "index": "test-index",
        "body": {
         "size": 0,
         "aggs": {
              "types_count" : { "value_count" : { "field" : "project.keyword" } }
              }
            }
        }
    },
    {
      "name": "table-flattened",
      "source": "table",
      "transform": [
            {
            "type": "formula",
            "as": "project",
            "expr": "datum.aggregations.types_count"
            },
            {"type": "identifier", "as": "boxposition"}
        ]
    }
 ],
   "marks": [
   {
      "type": "rect",
      "from": {"data": "table-flattened"},
      "encode": {
        "enter": {
          "x": {"scale": "x", "field": "boxposition"},
          "y": {"value": 5},
          "width": {"value": 100},
          "height": {"value": 55},
          "cornerRadius": {"value": 14},
          "border": {"value": 0},
        }
      }
    },   
    {
      "type": "text",
      "from": {"data": "table-flattened"},
      "encode": {
        "enter": {
          "text": {"field": "project"},
          "x": {"scale": "x", "field": "boxposition", "offset": 55},
          "y": {"value": 40},
          "align": {"value": "left"},
          "fontSize": {"value": 14},
          "fill": { "value": "white" }
        }
      }
    },
    {
      "type": "text",
      "from": {"data": "table-flattened"},
      "encode": {
        "enter": {
          "text": {"value": "Projects#"},
          "x": {"scale": "x", "field": "boxposition", "offset": 50},
          "y": {"value": 40},
          "align": {"value": "right"},
          "fontSize": {"value": 14},
          "fill": { "value": "white" }
        }
      }
    }
  ] 
} 

```

---

<div class="post-metadata">

**Author:** ![sam7](https://avatars.discourse-cdn.com/v4/letter/s/bc8723/32.png) [@sam7](https://discuss.elastic.co/u/sam7)\
**Post date:** [November 17, 2020, 1:16pm UTC](https://discuss.elastic.co/t/getting-error-x-is-not-a-function/255702/2 "2020-11-17T13:16:50Z")

</div>

No replies, any error that I am making in the script?

---

<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:** [December 15, 2020, 1:16pm UTC](https://discuss.elastic.co/t/getting-error-x-is-not-a-function/255702/3 "2020-12-15T13:16:58Z")

</div>

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