Filtering strings in Vega-Lite

Jump to Solution
779 1
Showing results for 
Search instead for 
Did you mean: 

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”,

1 Solution

Accepted Solutions

Solution from StackOverflow, FYI:

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

See Solution in Thread

1 Reply 1

Solution from StackOverflow, FYI:

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