# Help with window sort in vega

**URL:** <https://discuss.elastic.co/t/help-with-window-sort-in-vega/286783>\
**Category:** Kibana\
**Tags:** vega\
**Created:** [October 14, 2021, 11:16pm UTC](https://discuss.elastic.co/t/help-with-window-sort-in-vega/286783 "2021-10-14T23:16:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nsimi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nsimi/32/39013_2.png) [@nsimi](https://discuss.elastic.co/u/nsimi)\
**Post date:** [October 14, 2021, 11:16pm UTC](https://discuss.elastic.co/t/help-with-window-sort-in-vega/286783/1 "2021-10-14T23:16:59Z")

</div>

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:

```auto
{
  "$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!

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 15, 2021, 12:18am UTC](https://discuss.elastic.co/t/help-with-window-sort-in-vega/286783/2 "2021-10-15T00:18:01Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [October 15, 2021, 9:49pm UTC](https://discuss.elastic.co/t/help-with-window-sort-in-vega/286783/3 "2021-10-15T21:49:15Z")

</div>

Use [collect](https://vega.github.io/vega/docs/transforms/collect/) to sort.

```auto
{
  "$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](https://us1.discourse-cdn.com/elastic/original/3X/1/b/1b6c32f93a23749e7a8fe287b75ecca5bd8da3ca.png)

---

<div class="post-metadata">

**Author:** ![nsimi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nsimi/32/39013_2.png) [@nsimi](https://discuss.elastic.co/u/nsimi)\
**Post date:** [October 15, 2021, 10:04pm UTC](https://discuss.elastic.co/t/help-with-window-sort-in-vega/286783/4 "2021-10-15T22:04:43Z")

</div>

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

---

<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:** [November 12, 2021, 10:05pm UTC](https://discuss.elastic.co/t/help-with-window-sort-in-vega/286783/5 "2021-11-12T22:05:44Z")

</div>

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