modeling-dimension-tables
できること
このスキルは、国、地域、通貨、プランなどの記述的な参照テーブルを作ります。他のレポートは、これらのテーブルと結合します。すべての分析で一貫したラベルを使いたいデータチーム向けです。
使う場面
- ✓イベントや売上を、国、地域、プランでグループ化したいとき。
- ✓複数のレポートが再利用できる、共通の参照テーブルが必要なとき。
- ✓通貨や日付のテーブルを、モデルに追加したいとき。
スキルのリンク
https://github.com/PostHog/posthog/blob/master/products/data_modeling/skills/modeling-dimension-tables/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“国と地域の参照テーブルを作成し、売上を地域ごとにグループ化できるようにしてください。”
毎週5つの新しいスキル。1分で読めます。
仕組み
AIは、アップロードされたファイル、同期されたシステム、またはイベントから得た値から参照データを取得します。その後、各項目が1行になるように整え、ビューとして保存し、グループ化のためにメインのデータと結合します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Modeling dimension tables (star schema)
Dimensions are the descriptive tables (dim_country, dim_plan, dim_date) that fact tables join to for
slicing. This skill builds them once, cleanly, so every other model reuses them instead of re-deriving
lookups. Read modeling-warehouse-foundations first (joins + convertCurrency() live there). Catalog of
common dimensions: references/dimension-catalog.md; recipes in
references/posthog/ and references/dbt/.
Star schema in one screen
Facts (events, charges, revenue items) are long, keyed, and additive. Dimensions are short, one row per entity, descriptive. You model a dimension in three moves:
- Source it — where does the dimension data come from?
- Upload / seed a lookup (country→region, plan→tier) as a CSV (warehouse source or dbt seed).
- Sync it from a system of record (your app DB, Stripe products) as a warehouse source.
- Derive it from events (distinct countries seen, a plan property observed per person).
- Shape it — an aliased
SELECTwith clean column names, one row per entity (dedupe hard). Save as a view; materialize it on a slowsync_frequency(7day/30day) since dimensions change rarely and are read constantly. - Attach it — a saved join (dimension → a fact table) or person join (dimension → persons) so
its columns appear as native fields in any query, filter, or breakdown. See foundations
joins-and-dimensions.md.
Currency is already a managed dimension — don't build it
PostHog ships exchange rates behind convertCurrency(from, to, amount, timestamp?) (Open Exchange Rates,
historical-rate-correct). Use it directly for any money conversion. Only build a currency dimension yourself
in dbt (which has no equivalent), or if you need a rate provider PostHog doesn't offer.
Rules before you model
- One row per entity, unique key. A dimension with duplicate keys silently fan-outs every fact it joins.
Test uniqueness (PostHog: verify in the shaping query; dbt:
unique+not_null). - Drop NULL keys when you derive a dimension from events. HogQL keeps a row whose property is
missing when the filter only compares it to
'', so addisNotNull(...)as well. A NULL key becomes a dimension row of its own and it matches nothing on the fact side. - Alias to clean, stable names —
country_code,region,plan_tier. These names become the join surface everything else depends on. - Materialize static dimensions on a slow schedule; don't leave a constantly-read lookup virtual.
- Register and certify. Annotate the dimension and, if it's load-bearing, certify it in the catalog
(foundations
governance.md) so other models discover it and don't build a rival copy. - Prefer built-in currency (
convertCurrency) over a hand-rolled FX table on PostHog.
Build it
PostHog: shape an aliased dimension view, then materialize + join. Recipes:
references/posthog/dim_country.sql (derive + enrich from events),
dim_plan.sql (lookup/upload pattern).
dbt: conformed dim_* models with unique/not_null/relationships tests, plus a generated
dim_date. Recipes: references/dbt/.
File map
| File | Read when |
|---|---|
references/dimension-catalog.md |
Common dimensions, how to source each, and the natural key. |
references/posthog/ |
HogQL aliased-dimension view recipes. |
references/dbt/ |
dbt dim_date / dim_country + schema.yml tests. |
Companions
modeling-warehouse-foundations (joins + currency), setting-up-a-data-warehouse-source /
suggesting-data-imports (sync/upload the source data), and the models that consume these dimensions:
modeling-revenue-metrics, modeling-conversion-metrics, modeling-activation-metrics,
modeling-product-usage-metrics.
よくある質問
参照データはどこから来ますか?
アップロードしたファイル、同期しているシステム、またはPostHogのイベントに現れる値から来ます。
参照テーブルはどのくらいの頻度で更新されますか?
参照テーブルはめったに変わらないため、週次や月次のような遅めのスケジュールで更新されます。
スタースキーマとは何ですか?
イベントや支払いなどのメインのデータテーブルが、それを説明する小さな参照テーブルとつながる構造のことです。
詳細
作者による元の説明
Build reusable dimension / lookup tables for a star schema — country/region, timezone, currency, date, plan/product, and other descriptive attributes — on either PostHog data-warehouse views (HogQL) or an external dbt project. Use when the user wants to model dimension tables, lookup tables, a star schema, conformed dimensions, or wants to enrich events/revenue/usage with country, region, timezone, plan, or currency attributes without repeating JOINs. Covers sourcing the dimension data (upload, warehouse source, or derive from events), shaping it into an aliased one-row-per-entity view (option
repo: PostHog/posthog
人気
- GitHubのスター
- 41k
- ランキング
- #6850
- ライセンス
- —
- 更新日
- 2026/11/2
コメント
- …
このリポジトリの他のスキル
depot-ci
41kエージェントが、GitHub Actionsの代替であるDepot CIのワークフローを設定し実行できるよう支援します。既存のワークフローの移行や、実行ログの確認も含みます。
depot-container-builds
41kエージェントが、Depotのリモート・ビルダーでDockerイメージを作れるよう支援します。マルチプラットフォームのイメージ、レジストリへのプッシュ、ビルド失敗の修正を含みます。
depot-github-runners
41kエージェントが、GitHub Actionsのジョブを Depot が管理するランナーに移し、ランナーのサイズとラベルを選び、ランナー設定の問題を解決できるよう支援します。
editing-agents-md
41kエージェントが、AGENTS.mdとCLAUDE.mdのどちらにルールを書くべきかを判断し、ファイルを膨らませずに守られやすい形で書けるよう支援します。
似ているスキル
discrawl
394k保存済みのローカルなDiscordメッセージのアーカイブを検索して要約し、その新しさを確認し、ダイレクトメッセージを読めるようエージェントを支援します。
clickhouse-io
280kエージェントがClickHouseデータベースのクエリとスキーマを最適化できるようにします。高性能な分析処理向けのベストプラクティスを適用します。分析クエリが遅すぎるときに使います。
scientific-db-pubmed-database
280kエージェントが生物医学分野の科学論文を検索するのに役立ちます。特定の医療情報が必要な研究に便利です。