Help with window sort in vega

Hello All,

I am trying to get a window transform to sort data, and am having some issues, either my expectations are wrong or I am just doing something wrong:

{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "data": [
    {
      "name": "t2",
      "values": [{"value": 37}, {"value": 42}, {"value": 41}, {"value": 40}]
    },
    {
      "name": "t3",
      "source": "t2",
      "transform": [
        {
          "type":"window",
          "sort":{
            "order" :"descending",
            "field" : "value"
          }
        }
      ]
    }
  ],
  "marks": [
    {
      "type": "text",
      "encode": {
        "enter": {
          "text": "TEST",
          "fill": {"value": "#000"},
          "opacity": {"value": 1},
          "x": {"signal": "width / 2"},
          "y": {"signal": "height / 2"},
          "dx": {"value": 0},
          "angle": {"value": 0},
          "align": {"value": "center"},
          "baseline": {"value": "middle"},
          "font": {"value": "sans-serif"},
          "fontSize": {"value": 20},
          "fontStyle": {"value": "italic"},
          "fontWeight": {"value": "100"},
          "limit": {"value": 0}
        }
      }
    }
  ]
}

I expect the data to be in the table t3 in the order 37, 40, 41, 42 but its still in its original order what am I doing wrong here? I should be clear that this is just an example that I was trying to get it working the real thing I want to do it on later is a string.

Thank you!

I just wanted to drop a quick note that Vega is in Kibana, so to make sure you get the quickest response it's best if you post such questions in the Kibana category :slight_smile:

Use collect to sort.

{
  "$schema": "https://vega.github.io/schema/vega/v5.json",
  "data": [
    {
      "name": "t2",
      "values": [{"value": 37}, {"value": 42}, {"value": 41}, {"value": 40}]
    },
    {
      "name": "t3",
      "source": "t2",
      "transform": [{"type": "collect", "sort": {"field": "value"}}]
    }
  ]
}

image

Awesome thank you @aaron-nimocks !! +5 pts to Ravenclaw!

1 Like