cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
jasemilly
Helper I
Helper I

Basic Deneb Table change order of columns

Hi I have been following this tutorial and have it working on my own data, I would like to change the order of the columns but can't seem to figure it out or find any examples.

https://www.youtube.com/watch?v=2wZpdZ8hCik&t=466s 

Say I have

ColA     ColB   ColC

and I would like 

ColB  ColC   ColA

thanks for all ideas.

1 ACCEPTED SOLUTION
giammariam
Impactful Individual
Impactful Individual

If you don't want to bring in an additional sort order field into deneb, you could implement a transform to do the sorting and then use it in the x encoding: 

giammariam_0-1675954861121.png

If this is enough to get you going, please consider kudoing and choosing this reply as the solution. If you need additional help, let me know.

Full spec: 

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "width": {
    "step": 30
  },
  "data": {
    "url": "https://raw.githubusercontent.com/vega/vega-datasets/next/data/penguins.json"
  },
  "transform": [
    {"window": [{"op": "row_number", "as": "row_num"}]},
    {"filter": {"field": "row_num", "lte": "count"}},
    {"fold": ["Flipper Length (mm)", "Species", "Island", "Sex"]},
    {
      "calculate": "datum['key'] == 'Species' ? 1 : datum['key'] == 'Sex' ? 2 : datum['key'] == 'Island' ? 3 : datum['key'] == 'Flipper Length (mm)' ? 4 : null", "as": "key_sort"
    }
  ],
  "mark": "text",
  "encoding": {
    "y": {"field": "row_num", "type": "ordinal", "axis": null},
    "text": {"field": "value", "type": "nominal"},
    "x": {"field": "key", "sort": {"field": "key_sort"},"type": "nominal", "axis": {"orient": "top", "labelAngle": 0, "title": null, "domain": false, "ticks": false}, "scale": {"padding": 15}}
  }, "config": {"view": {"stroke": null}}
}

 



Madison Giammaria
Super User In Training‌ 😄
LinkedIn

View solution in original post

2 REPLIES 2
giammariam
Impactful Individual
Impactful Individual

If you don't want to bring in an additional sort order field into deneb, you could implement a transform to do the sorting and then use it in the x encoding: 

giammariam_0-1675954861121.png

If this is enough to get you going, please consider kudoing and choosing this reply as the solution. If you need additional help, let me know.

Full spec: 

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "width": {
    "step": 30
  },
  "data": {
    "url": "https://raw.githubusercontent.com/vega/vega-datasets/next/data/penguins.json"
  },
  "transform": [
    {"window": [{"op": "row_number", "as": "row_num"}]},
    {"filter": {"field": "row_num", "lte": "count"}},
    {"fold": ["Flipper Length (mm)", "Species", "Island", "Sex"]},
    {
      "calculate": "datum['key'] == 'Species' ? 1 : datum['key'] == 'Sex' ? 2 : datum['key'] == 'Island' ? 3 : datum['key'] == 'Flipper Length (mm)' ? 4 : null", "as": "key_sort"
    }
  ],
  "mark": "text",
  "encoding": {
    "y": {"field": "row_num", "type": "ordinal", "axis": null},
    "text": {"field": "value", "type": "nominal"},
    "x": {"field": "key", "sort": {"field": "key_sort"},"type": "nominal", "axis": {"orient": "top", "labelAngle": 0, "title": null, "domain": false, "ticks": false}, "scale": {"padding": 15}}
  }, "config": {"view": {"stroke": null}}
}

 



Madison Giammaria
Super User In Training‌ 😄
LinkedIn

@giammariam thank you again worked!!!

Helpful resources

Announcements
May 2023 update

Power BI May 2023 Update

Find out more about the May 2023 update.

Submit your Data Story

Data Stories Gallery

Share your Data Story with the Community in the Data Stories Gallery.

Top Solution Authors