long-metrics-table
Installation
SKILL.md
Skill: Managing Metrics and Dimensions in long-metrics.view.lkml
This document describes the pattern used in long-metrics.view.lkml for defining and aggregating metrics, and provides instructions on how to add new dimensions and measures.
Overview of the Pattern
The file long-metrics.view.lkml implements a long-table format (narrow format) for metrics to allow for flexible reporting. It uses derived tables and UNIONs to stack data for different metrics and timeframes.
- Base Fields & Aggregation Views: Views with
extension: required(likebase_fields,day_agg_fields) are used to share common fields across different aggregation levels. - Metric Specific Views: Views like
metric_total_sale_pricecompute window functions (running totals, rolling averages) over an explore source (order_items). - Combined View:
long_metricsuses a derived table with a series ofUNION ALLqueries to stack data for different metrics and timeframes into a single table. This view handles measures by filtering on ametricdimension.
How-To Guides
Adding a New Dimension from Products or Other Joined Views
If you want to add a new dimension (e.g., category from the products view, which is joined in the order_items explore):