set

Usage

view: view_name {
   set: set_name {
      fields: [field, field, ]
   }
}
Hierarchy
set
Possible Field Types
Dimension, Dimension Group, Filter Field, Measure

Accepts
A square-bracketed list of field names

Definition

Sets can be useful when referenced in other parameters, like fields (for joins) and drill_fields (for fields), that need lists of fields.

You define each set using the set parameter. A set can contain any number of dimensions, measures, or filter fields from the current view, including the individual dimensions generated by a dimension group. It can also contain fields from other views using the view_name.field_name syntax.

Inside the set parameter, you add a fields parameter and then list the fields, as in this example:

set: my_first_set {
  fields: [
    dimension_one,
    another_view.dimension_two,
    measure_one
  ]
}

Sets can also contain other sets. To differentiate a set name from the name of a dimension or measure, add a * character. For example:

set: my_first_set {
  fields: [
    dimension_one,
    another_view.dimension_two,
    measure_one
  ]
}

set: my_second_set {
  fields: [
    dimension_three,
    measure_two
  ]
}

set: my_third_set {
  fields: [
    my_first_set*,
    my_second_set*
  ]
}

The set named my_third_set will contain these fields:

  • dimension_one
  • another_view.dimension_two
  • measure_one
  • dimension_three
  • measure_two

Finally, fields can be excluded using the - character. For example:

set: my_first_set {
  fields: [
    dimension_one,
    another_view.dimension_two,
    measure_one
  ]
}

set: my_second_set {
  fields: [
    dimension_three,
    measure_two
  ]
}

set: my_third_set {
  fields: [
    my_first_set*,
    my_second_set*
  ]
}

set: my_fourth_set {
  fields: [
    my_first_set*,
    -measure_one
  ]
}

The set named my_fourth_set will contain these fields:

  • dimension_one
  • another_view.dimension_two

Examples

Make a set called financial_data

set: financial_data {
  fields: [
    subtotal,
    shipping,
    tax,
    total,
    cost,
    profit
  ]
}

Make a set called basic_customer_data in the Customers view that also references the Customer Order Facts view:

set: basic_customer_data {
  fields: [
    name,
    address,
    status,
    customer_order_facts.lifetime_orders,
    customer_order_facts.lifetime_revenue
  ]
}

Common challenges

Fields from another view must be joined to the Explore where set is being used

If you want to reference a field in set that is from another view, you need to make sure that view is joined to the Explore where set is being used. For example, this will not work:

Model File

explore: orders { ... }

View File

view: orders {
  set: customer_info {
    fields: [customer.name]
  }
}

Here customers hasn't been joined to orders, so a field from customers can't be referenced in the customer_info set.

Adding fields from a dimension_group to a set

When you want to add fields from a dimension_group to a set, you'll need to add each time frame dimension individually. For example, consider this dimension_group:

dimension_group: created {
  type: time
  timeframes: [date, week, month]
  sql: ${TABLE}.created_at ;;
}

You cannot add the day, week, and month dimension to a set like this:

set: created_timeframes {
  fields: [created]
}

Instead, you'll need to add the timeframes individually, like this:

set: created_timeframes {
  fields: [
    created_date,
    created_week,
    created_month
  ]
}