SQL
AuraScore 83/100

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.

Template

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

  1. Establish dbt configuration headers specifying incremental materialization, unique keys, and partition pruning on {{date_partition_col}}.
  2. Construct CTEs isolating time entries from {{billable_time_table}} filtered to the incremental lookback window.
  3. Implement point-in-time rate card resolution joining {{rate_card_table}} using non-equi window joins matching entry dates.
  4. Calculate billed hours, unbilled WIP, standard value, invoiced value, and write-down percentages per fee-earner and project.
  5. Compute Fee Earner Realization (Billed Amount / Standard Value) and Billing Realization (Collected Amount / Billed Amount).
  6. Derive direct labor cost per hour and margin percentages, classifying engagements meeting or failing {{engagement_margin_target}}.
  7. Aggregate partner distribution credits across shared engagement hierarchies with deterministic window partitions.
  8. 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

  1. Header Configuration Block: {{ config(...) }} dbt block.
  2. Complete SQL Script: Formatted CTEs terminating in a final SELECT * FROM final.
  3. 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.
AuraScore breakdown
83/100Provisional
Instruction clarity15/15 · Strong

Explicit role, a named task, and discrete steps the model can follow.

Context architecture12/12 · Strong

Background, inputs and variables the model needs before it starts.

Constraint engineering12/12 · Strong

Hard boundaries — what the model must and must not do.

Output specification6/14 · Thin

A named, field-level shape for the response.

Reasoning structure10/10 · Strong

Ordered work items that force analysis before an answer.

Model compatibility10/10 · Strong

Length and structure that travel across frontier models.

Token efficiency5/10 · Thin

Signal density — instruction weight without padding.

Reusability7/7 · Strong

Documented variables so the scaffold adapts to new inputs.

Robustness5/5 · Strong

Quality bar, assumptions and behaviour when inputs are thin.

Observed performance1/5 · Thin

How much real usage the template has behind it.

data-analytics
data-sql
professional-services
dbt
snowflake
profitability