
bi-fundamentals
BI fundamentals with metric definition, KPI calculation, dimensional modeling, dashboard optimization, and data storytelling. 40+ metric examples and calculation patterns.
- Installs
- 46
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/pluginagentmarketplace/custom-plugin-sql --skill bi-fundamentals- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads bi-fundamentals automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
Business Intelligence Fundamentals
Metric Definition & Calculation
Business Metrics
-- Core business metrics
-- Revenue metrics
SELECT
DATE_TRUNC('month', order_date)::DATE as month,
ROUND(SUM(amount), 2) as total_revenue,
COUNT(DISTINCT order_id) as order_count,
ROUND(SUM(amount) / COUNT(DISTINCT order_id), 2) as avg_order_value,
COUNT(DISTINCT customer_id) as unique_customers,
ROUND(SUM(amount) / COUNT(DISTINCT customer_id), 2) as revenue_per_customer
FROM orders
GROUP BY DATE_TRUNC('month', order_date)
ORDER BY month DESC;
-- Customer metrics
SELECT
customer_id,
COUNT(DISTINCT order_id) as lifetime_orders,
ROUND(SUM(amount), 2) as lifetime_value,
MIN(order_date) as first_order_date,
MAX(order_date) as last_order_date,
ROUND(DATEDIFF(DAY, MIN(order_date), MAX(order_date)) /
NULLIF(COUNT(DISTINCT order_id) - 1, 0), 2) as avg_days_between_orders,
ROUND(SUM(amount) / DATEDIFF(DAY, MIN(order_date), CURRENT_DATE), 4) as revenue_per_day
FROM orders
GROUP BY customer_id;
-- Product performance
SELECT
product_id,
product_name,
category,
COUNT(DISTINCT order_id) as order_count,
SUM(quantity) as units_sold,
ROUND(SUM(revenue), 2) as total_revenue,
ROUND(AVG(revenue), 2) as avg_order_value,
ROUND(SUM(profit), 2) as total_profit,
ROUND(100.0 * SUM(profit) / NULLIF(SUM(revenue), 0), 2) as profit_margin_pct
FROM order_items oi
JOIN products p ON oi.product_id = p.id
GROUP BY product_id, product_name, category
ORDER BY total_revenue DESC;
KPI Definitions
-- Key Performance Indicator calculations
-- Monthly Active Users (MAU)
SELECT
DATE_TRUNC('month', activity_date)::DATE as month,
COUNT(DISTINCT user_id) as mau
FROM user_activity
GROUP BY DATE_TRUNC('month', activity_date);
-- Customer Acquisition Cost (CAC)
SELECT
DATE_TRUNC('month', acquired_date)::DATE as month,
COUNT(DISTINCT customer_id) as new_customers,
ROUND(SUM(marketing_spend) / COUNT(DISTINCT customer_id), 2) as cac
FROM customers c
JOIN marketing_spend m ON EXTRACT(YEAR FROM c.acquired_date) = EXTRACT(YEAR FROM m.spend_date)
AND EXTRACT(MONTH FROM c.acquired_date) = EXTRACT(MONTH FROM m.spend_date)
GROUP BY DATE_TRUNC('month', acquired_date);
-- Customer Retention Rate
WITH monthly_activity AS (
SELECT
DATE_TRUNC('month', activity_date)::DATE as month,
customer_id
FROM orders
GROUP BY DATE_TRUNC('month', activity_date), customer_id
)
SELECT
current_month.month,
COUNT(DISTINCT current_month.customer_id) as current_month_customers,
COUNT(DISTINCT previous_month.customer_id) as retained_customers,
ROUND(100.0 * COUNT(DISTINCT previous_month.customer_id) /
COUNT(DISTINCT current_month.customer_id), 2) as retention_rate_pct
FROM monthly_activity current_month
LEFT JOIN monthly_activity previous_month
ON current_month.customer_id = previous_month.customer_id
AND current_month.month = previous_month.month + INTERVAL '1 month'
GROUP BY current_month.month
ORDER BY current_month.month;
-- Net Promoter Score (NPS) calculation
SELECT
department,
COUNT(CASE WHEN nps_score >= 9 THEN 1 END) as promoters,
COUNT(CASE WHEN nps_score >= 7 AND nps_score <= 8 THEN 1 END) as passives,
COUNT(CASE WHEN nps_score <= 6 THEN 1 END) as detractors,
COUNT(*) as total_responses,
ROUND(100.0 * (COUNT(CASE WHEN nps_score >= 9 THEN 1 END) -
COUNT(CASE WHEN nps_score <= 6 THEN 1 END)) / COUNT(*), 1) as nps_score
FROM customer_surveys
GROUP BY department;
Dimensional Modeling for BI
Fact Table Grain Selection
-- Atomic grain (transaction-level)
CREATE TABLE fact_sales_atomic (
transaction_id BIGINT PRIMARY KEY,
date_id INT,
customer_id INT,
product_id INT,
store_id INT,
quantity INT,
unit_price DECIMAL(10, 2),
net_sales DECIMAL(12, 2),
FOREIGN KEY (date_id) REFERENCES dim_date(date_id)
);
-- Summary grain (aggregated for performance)
CREATE TABLE fact_sales_summary (
summary_id BIGINT PRIMARY KEY,
date_id INT,
customer_segment VARCHAR(50),
product_category VARCHAR(50),
store_region VARCHAR(50),
transaction_count INT,
total_quantity INT,
total_sales DECIMAL(15, 2),
FOREIGN KEY (date_id) REFERENCES dim_date(date_id)
);
Dashboard Query Optimization
-- Optimized for dashboard performance using pre-aggregations
SELECT
d.month_name,
d.quarter,
d.year,
dpc.product_category,
dcs.customer_segment,
COUNT(*) as transaction_count,
SUM(fss.total_quantity) as units_sold,
ROUND(SUM(fss.total_sales), 2) as revenue,
ROUND(SUM(fss.total_sales) / COUNT(*), 2) as avg_transaction_value,
ROUND(SUM(fss.total_sales) / NULLIF(COUNT(DISTINCT dcs.customer_id), 0), 2) as revenue_per_customer
FROM fact_sales_summary fss
JOIN dim_date d ON fss.date_id = d.date_id
JOIN dim_product_category dpc ON fss.product_category = dpc.category_id
JOIN dim_customer_segment dcs ON fss.customer_segment = dcs.segment_id
WHERE d.year = EXTRACT(YEAR FROM CURRENT_DATE)
GROUP BY d.month_name, d.quarter, d.year, dpc.product_category, dcs.customer_segment
ORDER BY d.year DESC, d.quarter DESC, d.month_name DESC;
Trend & Variance Analysis
-- Year-over-year comparison
SELECT
EXTRACT(MONTH FROM order_date) as month,
EXTRACT(YEAR FROM order_date) as year,
ROUND(SUM(amount), 2) as monthly_revenue
FROM orders
GROUP BY EXTRACT(YEAR FROM order_date), EXTRACT(MONTH FROM order_date)
ORDER BY year DESC, month;
-- Budget vs Actual variance
SELECT
department,
EXTRACT(MONTH FROM report_date) as month,
SUM(budgeted_amount) as budget,
SUM(actual_amount) as actual,
SUM(actual_amount) - SUM(budgeted_amount) as variance,
ROUND(100.0 * (SUM(actual_amount) - SUM(budgeted_amount)) /
NULLIF(SUM(budgeted_amount), 0), 2) as variance_pct
FROM budget_actuals
GROUP BY department, EXTRACT(MONTH FROM report_date)
ORDER BY department, month DESC;
-- Cumulative variance analysis
WITH monthly_budget AS (
SELECT
department,
EXTRACT(MONTH FROM report_date) as month,
SUM(budgeted_amount) as budget,
SUM(actual_amount) as actual
FROM budget_actuals
GROUP BY department, EXTRACT(MONTH FROM report_date)
)
SELECT
department,
month,
budget,
actual,
SUM(actual) OVER (PARTITION BY department ORDER BY month) as ytd_actual,
SUM(budget) OVER (PARTITION BY department ORDER BY month) as ytd_budget,
SUM(actual) OVER (PARTITION BY department ORDER BY month) -
SUM(budget) OVER (PARTITION BY department ORDER BY month) as ytd_variance
FROM monthly_budget
ORDER BY department, month;
Advanced Analytics Calculations
-- Cohort lifetime value
WITH user_cohorts AS (
SELECT
DATE_TRUNC('month', customer_acquired_date)::DATE as cohort_month,
customer_id,
DATE_TRUNC('month', order_date)::DATE as order_month,
amount
FROM orders o
JOIN customers c ON o.customer_id = c.id
)
SELECT
cohort_month,
DATE_PART('month', order_month::timestamp - cohort_month::timestamp) / 1 as months_since_acquisition,
COUNT(DISTINCT customer_id) as cohort_size,
ROUND(SUM(amount), 2) as cohort_revenue
FROM user_cohorts
WHERE order_month >= cohort_month
GROUP BY cohort_month, months_since_acquisition
ORDER BY cohort_month, months_since_acquisition;
-- Customer segmentation with RFM analysis
WITH rfm AS (
SELECT
customer_id,
MAX(order_date) as last_order_date,
DATEDIFF(DAY, MAX(order_date), CURRENT_DATE) as recency,
COUNT(DISTINCT order_id) as frequency,
ROUND(SUM(amount), 2) as monetary,
NTILE(4) OVER (ORDER BY DATEDIFF(DAY, MAX(order_date), CURRENT_DATE) DESC) as r_score,
NTILE(4) OVER (ORDER BY COUNT(DISTINCT order_id)) as f_score,
NTILE(4) OVER (ORDER BY SUM(amount)) as m_score
FROM orders
GROUP BY customer_id
)
SELECT
customer_id,
CASE
WHEN r_score >= 3 AND f_score >= 3 AND m_score >= 3 THEN 'Champions'
WHEN r_score >= 3 AND f_score >= 3 THEN 'Loyal Customers'
WHEN f_score >= 3 THEN 'At Risk'
WHEN r_score = 4 THEN 'Lost'
ELSE 'Other'
END as segment,
frequency,
monetary,
recency
FROM rfm
ORDER BY monetary DESC;
Best Practices for BI
✅ Use conformed dimensions across all fact tables ✅ Pre-aggregate data for dashboard performance ✅ Implement slowly changing dimensions appropriately ✅ Create metrics at atomic grain level ✅ Use views for metric consistency ✅ Document metric definitions and calculations ✅ Implement data quality checks ✅ Monitor query performance with EXPLAIN PLAN ✅ Use appropriate indexes for BI queries ✅ Implement incremental loads for fact tables
FAQ
What does the bi-fundamentals skill do?
BI fundamentals with metric definition, KPI calculation, dimensional modeling, dashboard optimization, and data storytelling. 40+ metric examples and calculation patterns.
How do I install bi-fundamentals?
Run npx skills add https://github.com/pluginagentmarketplace/custom-plugin-sql --skill bi-fundamentals in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/bi-fundamentals/ (personal) or .claude/skills/bi-fundamentals/ (project).
Which AI agents can use bi-fundamentals?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is bi-fundamentals safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains bi-fundamentals?
It is published by pluginagentmarketplace in pluginagentmarketplace/custom-plugin-sql. It has 46 recorded installs.
More from pluginagentmarketplace/custom-plugin-sql
mysql
pluginagentmarketplace/custom-plugin-sql
MySQL database administration and development
data-analysis-sql
pluginagentmarketplace/custom-plugin-sql
SQL for data analysis with exploratory analysis, advanced aggregations, statistical functions, outlier detection, and business insights. 50+ real-world analytics queries.
data-warehouse
pluginagentmarketplace/custom-plugin-sql
Data warehouse design mastery with star schema, dimensional modeling, fact/dimension tables, slowly changing dimensions, and enterprise best practices. Complete schema examples included.
redis
pluginagentmarketplace/custom-plugin-sql
Redis data structures and commands including strings, lists, hashes, sets, sorted sets, streams, and transactions for high-performance caching and real-time applications.
postgresql
pluginagentmarketplace/custom-plugin-sql
PostgreSQL administration and setup including installation, configuration, backup/recovery, replication, and high-availability. Learn production PostgreSQL operations.
Popular data & databases skills
supabase-postgres-best-practices
supabase/agent-skills
Postgres best practices maintained by Supabase, for Postgres running anywhere. Load this skill BEFORE writing or changing anything that lives in a Postgres database: creating or altering tables and columns (including choosing column types), schema design, migrations and declarative schema files, RLS policies and the tests that verify them, indexes, triggers, database functions, queues and scheduled jobs (pgcron, pgmq), vector/semantic search (pgvector), and restoring dumps (pgrestore) or importing data. Also load it when diagnosing slow queries, high CPU, timeouts, EXPLAIN plans, connection exhaustion, locking, bloat, or rows visible to the wrong user or tenant. This is not just a performance guide — schema, migration, security, and SQL authoring tasks need these rules too, even for a one-column change or a single query.
prisma-client-api
prisma/skills
Prisma Client API reference covering model queries, filters, operators, and client methods. Use when writing database queries, using CRUD operations, filtering data, or configuring Prisma Client. Triggers on "prisma query", "findMany", "create", "update", "delete", "$transaction".
prisma-database-setup
prisma/skills
Deprecated compatibility name for prisma-orm-setup. Use only when a user or existing integration explicitly invokes prisma-database-setup; otherwise select prisma-orm-setup.
prisma-cli
prisma/skills
Prisma ORM 7 CLI reference for existing Prisma 7 applications or explicitly selected Prisma 7 workflows. Covers prisma init, generate, migrate, db, dev, studio, and mcp. For setup, connection repair, or Prisma 8, use prisma-orm-setup; not the Prisma Platform CLI.
prisma-postgres
prisma/skills
Deprecated compatibility name for prisma-postgres-setup. Use only when a user or existing integration explicitly invokes prisma-postgres; otherwise select prisma-postgres-setup.
prisma-driver-adapter-implementation
prisma/skills
Required reference for Prisma ORM 7 SQL driver adapter work. Use when implementing or modifying adapters, adding database drivers, or touching SqlDriverAdapter, Transaction, savepoint, result mapping, or DriverAdapterError behavior. Covers current transaction lifecycle, optional savepoint hooks, original database-error preservation, and verification.