Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/andresshm/fini-marketing-intelligence/llms.txt

Use this file to discover all available pages before exploring further.

The Fini Marketing Intelligence platform ships nine purpose-built SQL queries that feed the Power BI dashboards and downstream Python analytics. Each query targets either the fact_sales star-schema table — joined to dim_customers or dim_products where needed — or one of two enriched views: vw_sales_enriched and vw_product_launches. Together they cover executive-level KPIs, customer value segments, product performance, promotional impact, regional revenue distribution, seasonal demand patterns, and new-product launch velocity.
All queries that reference transactional data can also be run against vw_sales_enriched, which pre-joins fact_sales, dim_customers, and dim_products into a single flat view. Launch-specific queries use vw_product_launches, which adds launch_date and days_since_launch to every sale row.

Executive & Financial

Source file: sql/analytics/executive_kpis.sql
Primary table: fact_sales
Returns a single aggregated row of top-line business metrics for use in executive dashboards and summary scorecards.
SELECT
    COUNT(*) AS total_sales,
    SUM(revenue) AS total_revenue,
    SUM(margin) AS total_margin,
    AVG(revenue) AS avg_sale_value,
    SUM(units) AS total_units_sold
FROM fact_sales;
ColumnTypeDescription
total_salesintegerTotal number of individual sale transactions
total_revenuenumericSum of revenue across all transactions
total_marginnumericSum of gross margin across all transactions
avg_sale_valuenumericMean revenue per transaction
total_units_soldintegerTotal units sold across all products

Customer Analytics

Source file: sql/analytics/customer_segments.sql
Primary tables: fact_sales JOIN dim_customers
Aggregates revenue and purchase behaviour by the purchase_frequency dimension stored in dim_customers, enabling comparison of Low, Medium, and High frequency buyer segments.
SELECT
    c.purchase_frequency,
    COUNT(DISTINCT c.customer_id) AS customers,
    ROUND(SUM(f.revenue)::numeric, 2) AS revenue,
    ROUND(AVG(f.revenue)::numeric, 2) AS avg_sale
FROM fact_sales f
JOIN dim_customers c
    ON f.customer_id = c.customer_id
GROUP BY c.purchase_frequency
ORDER BY revenue DESC;
ColumnTypeDescription
purchase_frequencytextCustomer segment label (Low, Medium, High) from dim_customers
customersintegerNumber of distinct customers in this frequency segment
revenuenumericTotal revenue contributed by the segment, rounded to 2 decimal places
avg_salenumericAverage transaction revenue for customers in the segment

Product Performance

Source file: sql/analytics/top_products.sql
Primary tables: fact_sales JOIN dim_products
Returns the ten highest-revenue products, enriched with category, margin, and unit volume. Used to identify hero SKUs and category leaders in product performance reports.
SELECT
    p.product_name,
    p.category,
    SUM(f.units) AS units_sold,
    ROUND(SUM(f.revenue)::numeric, 2) AS revenue,
    ROUND(SUM(f.margin)::numeric, 2) AS margin
FROM fact_sales f
JOIN dim_products p
    ON f.product_id = p.product_id
GROUP BY
    p.product_name,
    p.category
ORDER BY revenue DESC
LIMIT 10;
ColumnTypeDescription
product_nametextDisplay name of the product from dim_products
categorytextProduct category (e.g. Gummies, Belts, Seasonal)
units_soldintegerTotal units sold for this product across all transactions
revenuenumericTotal revenue generated by the product
marginnumericTotal gross margin generated by the product
Results are ordered by revenue DESC and capped at the top 10 products.
Source file: sql/analytics/seasonality_analysis.sql
Primary tables: fact_sales JOIN dim_products
Breaks down unit volume by calendar month and product season tag, exposing demand patterns across the year. Useful for production planning and seasonal campaign scheduling.
SELECT
    EXTRACT(MONTH FROM f.sale_date) AS month,
    p.season,
    SUM(f.units) AS units_sold
FROM fact_sales f
JOIN dim_products p
    ON f.product_id = p.product_id
GROUP BY
    month,
    p.season
ORDER BY
    month,
    p.season;
ColumnTypeDescription
monthnumericCalendar month number (1 = January … 12 = December) extracted from sale_date
seasontextSeason label assigned to the product in dim_products (e.g. Summer, Halloween, All Year)
units_soldintegerTotal units sold for that month–season combination

Promotions

Source file: sql/analytics/promotion_analysis.sql
Primary table: fact_sales
Groups all transactions by discount level, showing how average unit volume, revenue, and margin shift across each discount tier. Provides the quantitative foundation for promotion ROI decisions.
SELECT
    discount,
    COUNT(*) AS transactions,
    ROUND(AVG(units)::numeric, 2) AS avg_units,
    ROUND(AVG(revenue)::numeric, 2) AS avg_revenue,
    ROUND(AVG(margin)::numeric, 2) AS avg_margin
FROM fact_sales
GROUP BY discount
ORDER BY discount;
ColumnTypeDescription
discountnumericDiscount rate applied to the transaction (e.g. 0, 0.10, 0.20)
transactionsintegerNumber of transactions at this discount level
avg_unitsnumericMean units sold per transaction at this discount level
avg_revenuenumericMean revenue per transaction at this discount level
avg_marginnumericMean gross margin per transaction at this discount level

Regional Performance

Source file: sql/analytics/sales_by_region.sql
Primary tables: fact_sales JOIN dim_customers
Aggregates revenue, margin, and unit volume by customer region, enabling geographic performance comparisons and identification of under-served markets.
SELECT
    c.region,
    ROUND(SUM(f.revenue)::numeric, 2) AS revenue,
    ROUND(SUM(f.margin)::numeric, 2) AS margin,
    SUM(f.units) AS units
FROM fact_sales f
JOIN dim_customers c
    ON f.customer_id = c.customer_id
GROUP BY c.region
ORDER BY revenue DESC;
ColumnTypeDescription
regiontextGeographic region label from dim_customers (e.g. North, South, East, West)
revenuenumericTotal revenue generated by customers in this region
marginnumericTotal gross margin generated by customers in this region
unitsintegerTotal units sold to customers in this region

Product Launch Tracking

Source file: sql/analytics/launch_velocity.sql
Primary view: vw_product_launches
Plots average daily revenue against days-since-launch for the first 90 days across all products, revealing the typical ramp-up curve for new SKUs at Fini.
SELECT
    days_since_launch,
    ROUND(AVG(revenue)::numeric,2) AS avg_revenue
FROM vw_product_launches
WHERE days_since_launch <= 90
GROUP BY days_since_launch
ORDER BY days_since_launch;
ColumnTypeDescription
days_since_launchintegerNumber of days elapsed since the product’s launch date (0–90)
avg_revenuenumericMean daily revenue across all products at this specific day post-launch
Source file: sql/analytics/top_launches.sql
Primary view: vw_product_launches
Ranks every product by total revenue accumulated within its first 90 days on the market. The primary query for identifying breakout new products.
SELECT
    product_name,
    ROUND(SUM(revenue)::numeric,2) AS revenue,
    ROUND(SUM(margin)::numeric,2) AS margin,
    SUM(units) AS units
FROM vw_product_launches
WHERE days_since_launch <= 90
GROUP BY product_name
ORDER BY revenue DESC;
ColumnTypeDescription
product_nametextName of the launched product
revenuenumericCumulative revenue in the first 90 days post-launch
marginnumericCumulative gross margin in the first 90 days post-launch
unitsintegerTotal units sold in the first 90 days post-launch
Source file: sql/analytics/category_launches.sql
Primary view: vw_product_launches
Summarises launch performance at category level for the first 90 days, showing which product families perform best when introducing new SKUs.
SELECT
    category,
    ROUND(SUM(revenue)::numeric,2) AS revenue,
    ROUND(SUM(margin)::numeric,2) AS margin
FROM vw_product_launches
WHERE days_since_launch <= 90
GROUP BY category
ORDER BY revenue DESC;
ColumnTypeDescription
categorytextProduct category from vw_product_launches (e.g. Gummies, Belts, Seasonal)
revenuenumericCumulative revenue for new products in this category within the first 90 days
marginnumericCumulative gross margin for new products in this category within the first 90 days

Build docs developers (and LLMs) love