Views
Views sit on top of the data graph of cubes and create a facade of your whole data model with which data consumers can interact. They are useful for defining metrics, managing governance and data access, and controlling ambiguous join paths.
Views can not have their own members. Instead, use the includes
property
to include measures and dimensions from other cubes into the view. In the
example below, we create a new view ActiveUsers
which is made up of properties
from the Users
cube:
view(`ActiveUsers`, {
description: `14 days rolling count of active users`,
includes: [
// Measure
Users.rolling_count,
// Dimensions
Users.city,
Users.created_at,
],
});
You also can reference measures and dimensions one-by-one. This is helpful when
there is a need to control the join path or to
rename measures and dimensions from the underlying cubes. In the example below,
we create a view CompletedOrders
which brings in dimensions from the Users
cube through nested joins:
view(`CompletedOrders`, {
description: 'Count of completed orders',
includes: [Orders.completed_count],
measures: {
count: {
sql: `${Orders.completed_count}`,
type: `number`,
},
},
// In the example below we are controlling the join path with a nested path
// to the underlying member.
dimensions: {
userCity: {
sql: `${Orders.Users.city}`,
type: `string`,
},
},
});
Views can be queried the same way as cubes; the example below show how to query the above view with SQL API:
SELECT
count,
userCountry
FROM CompletedOrders
GROUP BY 2
Views also do not define any pre-aggregations, instead they re-use pre-aggregations defined by the underlying cubes.
A description of the view allows your team to better understand what its purpose is. It is a very simple and yet useful tool that gives a hint to everyone and ensures that data is interpreted correctly by users.
view(`ActiveUsers`, {
description: `14 days rolling count of active users`,
});
The includes
property is used to bulk add measures or dimensions to a view.
view(`ActiveUsers`, {
description: `14 days rolling count of active users`,
includes: [
// Measure
Users.rolling_count,
// Dimensions
Users.city,
Users.created_at,
],
});
The shown
property is used to manage the visibility of a view. Valid values
for shown
are true
and false
.
view(`ARR`, {
description: `Annual Recurring Revenue`,
shown: true,
includes: [Revenue.arr, Revenue.date, Customers.plan],
});
To learn more about using shown
to control visibility based on security
context, read the Controlling access to cubes and views
recipe.
Did you find this page useful?