Partner Realization and Fee Earner Profitability dbt Pipeline Engine
Generates an advanced modular dbt SQL model calculating fee earner realization, margin, and partner profit allocation.
Use this prompt when architecting robust analytics engineering models for consulting and legal practices. It creates incremental SQL models with test blocks and window functions tailored for partner compensation and billable margin metrics.
Role: Principal Analytics Engineer specializing in billable utilization and partner equity metrics within professional services.
Context
- Target SQL dialect and warehouse: {{sql_dialect}}
- Production schema name: {{target_schema}}
- Source timecard entries table: {{billable_time_table}}
- Agreed and rack rate table: {{rate_card_table}}
- Profit margin performance benchmark: {{engagement_margin_target}}
- Incremental date clustering column: {{date_partition_col}}
Task
Author a modular, production-grade {{sql_dialect}} script structured as a modern dbt incremental model that ingests {{billable_time_table}}, joins {{rate_card_table}}, and computes fee-earner billable realization, effective hourly rate (EHR), write-downs, and practice group partner profitability against {{engagement_margin_target}}.
Method
- Establish dbt configuration headers specifying incremental materialization, unique keys, and partition pruning on {{date_partition_col}}.
- Construct CTEs isolating time entries from {{billable_time_table}} filtered to the incremental lookback window.
- Implement point-in-time rate card resolution joining {{rate_card_table}} using non-equi window joins matching entry dates.
- Calculate billed hours, unbilled WIP, standard value, invoiced value, and write-down percentages per fee-earner and project.
- Compute Fee Earner Realization (Billed Amount / Standard Value) and Billing Realization (Collected Amount / Billed Amount).
- Derive direct labor cost per hour and margin percentages, classifying engagements meeting or failing {{engagement_margin_target}}.
- Aggregate partner distribution credits across shared engagement hierarchies with deterministic window partitions.
- Emit clean dimensional attributes, metrics, and metadata timestamps in the final query projection.
Constraints
- MUST be fully syntactically valid in {{sql_dialect}} without pseudo-code.
- MUST use standard Common Table Expression (CTE) styling with single-responsibility steps.
- MUST NOT use correlated subqueries or unindexed scalar subqueries inside SELECT clauses.
- All division operations MUST include NULLIF or zero-division protections.
Output format
- Header Configuration Block:
{{ config(...) }}dbt block. - Complete SQL Script: Formatted CTEs terminating in a final
SELECT * FROM final. - Inline Schema Test YAML: Schema documentation defining unique, not_null, and custom dbt-expectations tests.
Self-review
- Verify all zero-division edge cases across realization calculations return NULL instead of runtime exceptions.
- Ensure incremental logic correctly prunes partitions on {{date_partition_col}} during standard runs.
- Confirm fee-earner hierarchy rollups do not produce duplicate grain records.
Explicit role, a named task, and discrete steps the model can follow.
Background, inputs and variables the model needs before it starts.
Hard boundaries — what the model must and must not do.
A named, field-level shape for the response.
Ordered work items that force analysis before an answer.
Length and structure that travel across frontier models.
Signal density — instruction weight without padding.
Documented variables so the scaffold adapts to new inputs.
Quality bar, assumptions and behaviour when inputs are thin.
How much real usage the template has behind it.