Filtering strings in Vega-Lite

Hi all,

I would like to filter my records inside the vega-lite app to be independent from various views. Therefore I’m looking for a way to filter strings:

  1. record: “ABCD”
  2. record: “ABKF”
  3. record: “APFK”

I want to visualise only records where the string starts with “AB”. As far as I read the documentation, it is possible to filter numbers and complete strings. But is it possible to truncate strings? Or maybe there is another workaround? I expect to use it inside the transform statement.

“$schema”: “”,
“transform”: [
“filter”:{truncate(“field”:“PL reference”, 4)}, //something here is fishy…
“title”: “Shipment”,
“width”: “container”,
“height”: “container”,
“mark”: “bar”,
“encoding”: {
“x”: {
“type”: “nominal”,
“type”: “quantitative”,
“field”: “PL reference”,

Solution from StackOverflow, FYI:

"transform": [{"filter": "slice(datum.key, 0, 2) == 'AB'"}]

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