Skip to content

Instantly share code, notes, and snippets.

@ducchetrongminh
Last active May 29, 2024 10:55
Show Gist options
  • Save ducchetrongminh/e358f6557c083e7fb59d24abfaf9f585 to your computer and use it in GitHub Desktop.
Save ducchetrongminh/e358f6557c083e7fb59d24abfaf9f585 to your computer and use it in GitHub Desktop.
Reuse dashboard components with Holistics

This gist demonstrate how you can reuse dashboard components using Holistics' feature "dashboard as-code".

You can read more about "dashboard as-code" at:

  • Dashboard As Code (Docs)
  • Reusable Components in Canvas Dashboard (Docs)
  • Build a Dashboard with Multiple Similar Charts (Docs)
  • AML Extend (Docs)
// _template/seller.dataset.aml
Model order_items_SELLER_ID = brazil_ecommerce_order_items.extend({
type: 'query',
models: [brazil_ecommerce_order_items],
query: @sql
SELECT * FROM {{ #brazil_ecommerce_order_items }}
WHERE seller_id = 'SELLER_ID'
;;
})
Model orders_SELLER_ID = brazil_ecommerce_orders.extend({
type: 'query',
models: [brazil_ecommerce_orders, order_items_SELLER_ID],
query: @sql
SELECT o.*
FROM {{ #brazil_ecommerce_orders AS o }}
JOIN {{ #order_items_SELLER_ID as oi }} USING (order_id)
;;
})
Dataset seller_SELLER_ID {
label: 'Seller SELLER_ID'
data_source_name: 'demodb'
models: [
orders_SELLER_ID,
order_items_SELLER_ID
]
relationships: [
relationship(order_items_SELLER_ID.order_id > orders_SELLER_ID.order_id, true)
]
owner: '[email protected]'
}
// models/brazil_ecommerce_order_items.model.aml
Model brazil_ecommerce_order_items {
type: 'table'
label: 'Order Items'
description: ''
data_source_name: 'demodb'
dimension order_id {
label: 'Order Id'
type: 'text'
hidden: false
definition: @sql {{ #SOURCE.order_id }};;
}
dimension product_id {
label: 'Product Id'
type: 'text'
hidden: false
definition: @sql {{ #SOURCE.product_id }};;
}
dimension seller_id {
label: 'Seller Id'
type: 'text'
hidden: false
definition: @sql {{ #SOURCE.seller_id }};;
}
dimension price {
label: 'Price'
type: 'number'
hidden: false
definition: @sql {{ #SOURCE.price }};;
}
measure revenue {
label: "Revenue"
type: "number"
definition: @sql SUM({{ price }});;
aggregation_type: "custom"
format: "[\$\$]#,###"
}
owner: '[email protected]'
table_name: '"brazil_ecommerce"."order_items"'
}
// models/brazil_ecommerce_orders.model.aml
Model brazil_ecommerce_orders {
type: 'table'
label: 'Orders'
description: ''
data_source_name: 'demodb'
dimension order_id {
label: 'Order Id'
type: 'text'
hidden: false
definition: @sql {{ #SOURCE.order_id }};;
}
dimension customer_id {
label: 'Customer Id'
type: 'text'
hidden: false
definition: @sql {{ #SOURCE.customer_id }};;
}
dimension order_status {
label: 'Order Status'
type: 'text'
hidden: false
definition: @sql {{ #SOURCE.order_status }};;
}
dimension order_purchase_timestamp {
label: 'Order Purchase Timestamp'
type: 'datetime'
definition: @sql {{ #SOURCE.order_purchase_timestamp }};;
}
owner: '[email protected]'
table_name: '"brazil_ecommerce"."orders"'
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment