# KQL formula in vega lite

**URL:** <https://discuss.elastic.co/t/kql-formula-in-vega-lite/328420>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [March 24, 2023, 5:03am UTC](https://discuss.elastic.co/t/kql-formula-in-vega-lite/328420 "2023-03-24T05:03:19Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nanditha](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nanditha/32/137350_2.png) [@Nanditha](https://discuss.elastic.co/u/Nanditha)\
**Post date:** [March 24, 2023, 5:03am UTC](https://discuss.elastic.co/t/kql-formula-in-vega-lite/328420/1 "2023-03-24T05:03:19Z")

</div>

Hi Team,

I'm trying to plot a line graph using vega-lite. How to give KQL formulas in vega-lite. I used field called "claculate" but may be my syntax is wrong. Please help on creating line graph.

```auto
{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "title": "Performance metrics",
  "data": {
    "url": {
      "%context%": true,
      "%timefield%": @timestamp,
      "index": "bkp-ispfw-15032023"
    }
  },
  "transform": [
    {
      "calculate": "count(kql='Status: \"TP\"')/(count(kql='ValidGTPoint:\"True\"'))", "as": "PDJ Score" 
    }
  ],
  "mark": {
    "type": "line",
    "point": true
  },
  "encoding": {
    "x": {"timeUnit": "year", "field": "date"},
    "y": {"aggregate":"mean", "field": "price", "type": "quantitative"},
    "color": {"field": "symbol", "type": "nominal"}
  }
}

```

Error its not showing which line and any other details. Just giving below error.  
`Unexpected token =`

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![Marco\_Liberati](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marco_liberati/32/82953_2.png) [@Marco\_Liberati](https://discuss.elastic.co/u/Marco_Liberati)\
**Post date:** [March 24, 2023, 8:45am UTC](https://discuss.elastic.co/t/kql-formula-in-vega-lite/328420/2 "2023-03-24T08:45:44Z")

</div>

Hi @Nanditha

it looks like you are using a Lens formula within a Vega context: that is not possible as formula is a Lens specific feature.  
You have to manually create a query to retrieve 2 filtered counts, and then perform the Vega calculation on the fields.

---

<div class="post-metadata">

**Author:** ![Nanditha](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nanditha/32/137350_2.png) [@Nanditha](https://discuss.elastic.co/u/Nanditha)\
**Post date:** [April 10, 2023, 8:08am UTC](https://discuss.elastic.co/t/kql-formula-in-vega-lite/328420/3 "2023-04-10T08:08:01Z")

</div>

Can you please show me an example or any link to explain.

---

<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:** [May 8, 2023, 8:08am UTC](https://discuss.elastic.co/t/kql-formula-in-vega-lite/328420/4 "2023-05-08T08:08:34Z")

</div>

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