Search code examples
powerbivisualizationpowerbi-desktopvegadeneb

select specific columns from a dataset using Vega


If I have a dataset with 7 fields named by letters a, b, .., g, and want to transform it to just 3 columns b, d, f, then how can it be done?

The aggregate transform can be used but as I'm doing a selection, not an aggregation, this seems unnatural.

Here's what the aggregate would look like:

{
  "name": "selected_columns_data",
  "source": "dataset",
  "transform": [
   {
          "type": "aggregate",
          "ops": [],
          "fields": [],
          "groupby": ["b", "d", "f"]
   }
  ]
}

I'm doing this for the purpose of letting the user decide which columns to show in a vega table - if you have a better way, please let me know.


Solution

  • You want the project transform.

    https://vega.github.io/vega/docs/transforms/project/