Spiega documentation
- Knowledge sharing
- Portfolio
business intelligence
BI, dashboards, data visualization
business intelligence
Collecting data has one main purpose: gain insights about your business and make conscious data-driven decisions. This is why we need to create:
- data model
- to organize the information in a structured, searchable data scheme
- metadata
- how data are organized inside the organization
- pipelines
- the data transformation you need
- storage
- where and how your data get stored
- query
- how you retrieve the data
- visualize
- create visual representations
- report
- create reports and forecasts
All this steps sit in a perpetual circle where each iteration is re-purposed and improved over time as business requirements or input data change.
process
Business intelligence sits in between of input data and insights. It is really crucial to understand:
- input data
- operations
- insights
- business value
Business intelligences keeps on improving and adapting to each moving component to optimize data processing and provide faster and more insightful results.
The process works at such:
- sources
- understand the sources and map them
- link
- find the keys to join data sources
- compliance
- understand what type of data and where to store them
- data model
- iterate on a data model which is compatible to standards and provide the correct usage of the data
- storage
- where and how to store the data
- pipelines
- create the proper data transformation
- real time
- real time data processing
- more heavy weighted process
- what test we run on the data
- how to display the data
- interface
- how to process the data
- needs
- what is the final information we need (finance forecast, operational productivity, costs…)
To create an efficient business intelligence we have two
- Experience in building Data Functions & a single source of truth from scratch.
- AI & Data enablement - Your experience in and vision for enabling an orgs systematically and in a scalable way.
- Strategy & Change Management - How you lead through large technical & culture change.
- Collaboration & ownership – Working cross-functionally with technical & non-technical staff across Product, Engineering, Operations, Compliance and GTM. How you deal with ambiguity.
data model
It is essential to create a proper data model to create structures where both atomistic and aggregated information are stored in a persistent way:
- index
- all data sources should have a joining index
- hierarchy
- how entities are linked together
- consistency
- entries don’t have colliding meaning
- compliance
- data should be processed and stored considering the privacy and retention of the data. Sensitive data should be kept as indices but not reachable
metadata
To efficiently access the data and understand what is the best way to create a pipeline or query the data we need to provide consistent metadata to describe the content of directories and tables. We should periodically review the content and understand whether we need to test different strategies. Metadata should contain the table description and how tables can be linked together, what is the best index to join tables and whether there is an aggregated version which will improve performance.
pipelines
real time
batch processes
storage
query
dbt
Dbt is “data build tool” focused for business intelligence and data transformation. It treats a warehouse as a computing engine:
- version
- version control data transformation
- SQL
- compatible
- quality assurance
- built-in mechanism to define test cases
- documentation
- generated from the process, helping debugging
- modular
- models shared across organization
- performance
- dbt can optimize SQL performances
- collaborative
- easier to share models
- examples
#python -m pip install dbt dbt-mysqlcd ~/lav/src/sawmill/mkdir -p dbt_sawmillcd dbt_sawmilldbt initInstalling dbt project and profile setupInfo Created .vscode/extensions.json with dbt extension recommendationSuccess Project created successfully!Info Project name: jaffle_shopInfo Project directory: jaffle_shopInfo Setting up your profile...Info Creating new profile...==================== Execution Summary =====================Finished 'init' with 1 error [336ms]dbt_project.ymlname: my_projectprofile: my_dbt_profilemodel-paths: ["models"]analysis-paths: ["analyses"]test-paths: ["tests"]seed-paths: ["seeds"]target-paths: ["target"]clean-paths: ["clean"]models:my_project:my_model:+materialized: table- Defining Models
One of the most common use cases is defining transformation models in SQL files. dbt allows you to write modular SQL that builds upon other models, creating a layered approach to data transformation.
-- models/raw/my_table.sqlSELECTcustomer_id,order_date,amount,product_categoryFROM raw_source_table-- models/stg/stg_customer_orders.sql{{ config(materialized='table') }}SELECTcustomer_id,DATE(order_date) as order_date,ROUND(amount, 2) as amountFROM {{ ref('my_table') }}WHERE amount > 0-- models/marts/customer_lifetime_value.sql{{ config(materialized='table') }}SELECTcustomer_id,SUM(amount) as total_spend,COUNT(order_date) as order_count,AVG(amount) as avg_order_valueFROM {{ ref('stg_customer_orders') }}GROUP BY customer_id- Testing and Quality Assurance
dbt provides built-in testing capabilities that run automatically when you execute your data pipeline. This ensures data quality before it reaches business intelligence tools.
-- models/stg/stg_customer_orders.sqlSELECTcustomer_id,DATE(order_date) as order_date,ROUND(amount, 2) as amountFROM {{ ref('my_table') }}WHERE amount > 0{{ config(materialized='table') }}-- tests/customers_have_orders.sql{{ config(materialized='table') }}SELECT *FROM {{ ref('stg_customer_orders') }}WHERE customer_id IS NULL# test unique customers{{ test_unique('customer_id') }}# test not null on customer_id{{ test_not_null('customer_id') }}# test amount is positive{{ test_where('amount > 0') }}# test that orders come after a specific date{{ test_where('order_date >= date(\'2023-01-01\')') }}- Documentation Generation
dbt automatically generates documentation based on your model definitions and tags. This documentation includes data lineage, field descriptions, and test coverage, making it easier for stakeholders to understand your data assets.
-- models/marts/customer_lifetime_value.sql{{ config(materialized='table',description='Aggregate metrics for customer lifetime value calculation',tags=['finance', 'customer-analytics', 'revenue']) }}SELECTcustomer_id,SUM(amount) as total_spend,COUNT(order_date) as order_count,AVG(amount) as avg_order_valueFROM {{ ref('stg_customer_orders') }}GROUP BY customer_id# dbt generate docs will create documentation automaticallydbt docs generate
- Using Jinja for Dynamic Logic
dbt supports Jinja templating for dynamic SQL generation. This allows you to create more flexible and reusable transformations without duplicating code.
-- models/marts/sales_report.sql{{ config(materialized='table') }}WITH daily_sales AS (SELECTDATE_TRUNC('day', order_date) as sale_day,SUM(amount) as daily_revenueFROM {{ ref('stg_customer_orders') }}GROUP BY 1)SELECTsale_day,daily_revenue,ROW_NUMBER() OVER (ORDER BY sale_day DESC) as rnFROM daily_salesWHERE rn <= 30-- Parameters can be passed via dbt run command-- dbt run --target production --vars '{"report_start_date": "2024-01-01"}'- Running and Scheduling
Execute dbt commands to build, test, and deploy your data models. This workflow ensures changes go through a proper validation pipeline before production use.
# Run all models in developmentdbt run --target development# Run a specific modeldbt run --select models/marts/customer_lifetime_value.sql# Run tests onlydbt test# Clean up and re-rundbt clean && dbt run# Schedule with cron# 0 2 * * * cd /path/to/dbt && dbt run > dbt.log 2>&1# Schedule via cron job(dbt "run" "--profiles-dir" "/home/user/.dbt")- dbt Core and Cloud
dbt offers two versions: Core for open-source usage and Cloud for managed infrastructure.
# Core installationpip install dbt-core# Install from sourcepip install dbt-core[all]# Cloud installationpip install dbt-cloud- Common Use Cases
Here are practical scenarios demonstrating dbt’s capabilities in business intelligence workflows:
- Revenue Analysis Pipeline- Extract: Pull transaction data from the source system- Transform: Clean, aggregate, and enrich with product categories- Load: Write to a star schema for BI tool consumption- Test: Validate revenue totals match financial reports- Customer Segmentation- Raw: Import customer transaction history- Intermediate: Calculate recency, frequency, monetary metrics- Final: Create RFM segments for marketing campaigns- Document: Explain segmentation logic to business team- Inventory Forecasting- Historical: Extract sales and inventory data- Aggregation: Group by product and time period- Prediction: Apply forecasting models- Action: Flag items needing reorder- End-to-End Example- dbt run --models marts.*- dbt test --models marts.*- dbt docs generate- dbt docs serve- Integration with BI Tools
Once dbt models are built and validated, export them for use in visualization tools.
- SQL Direct- Most BI tools can connect directly to the data warehouse- Reference dbt models by their names- Example: =SELECT * FROM {{ ref('customer_lifetime_value') }}=- dbt Analytics Hub- Export models to Snowflake or BigQuery- Share with teams who don't have dbt access- Maintain version control and lineage tracking- Data Warehouse Views- dbt can create views on top of materialized tables- Simplify queries for end users- Example: =CREATE VIEW mart.customer_summary AS SELECT * FROM {{ ref('customer_lifetime_value') }}=- Advanced Patterns
For more sophisticated use cases, dbt supports complex patterns including incremental models, snapshots, and semantic layer definitions.
-- models/incremental/sales_incremental.yml{{ config(materialized='incremental',unique_key='transaction_id',target_partitions='date',incremental_strategy='merge',on_schema_change='sync_all_columns') }}SELECTtransaction_id,customer_id,amount,CURRENT_TIMESTAMP as updated_atFROM source_table{{ get_incremental_clause() }}-- Semantic Layer{{ config(enabled=True,meta={"dbt_semantic_layer": {"default_time_dimension": "order_date","default_time_grain": "day","metrics": ["total_amount", "unique_customers"]}}) }}- Best Practices
To maximize dbt effectiveness in business intelligence projects, follow these guidelines:
1. Model Organization- Raw: Extract data as-is from sources- Staged: Clean and normalize for consistency- Mart: Business-ready aggregated views2. Naming Convention- Prefix with source system (e.g., raw_stripe_customers)- Use clear model names (e.g., stg_customer_orders)- Group by business domain (e.g., marts_revenue)3. Version Control- Track all SQL changes in Git- Use meaningful commit messages- Tag releases for major business changes4. Collaboration- Write clear, documented SQL- Add tests for data quality- Generate and maintain documentation5. Performance- Materialize large models as tables- Use incremental updates where possible- Partition by time when appropriate - Conclusion **
dbt transforms how teams approach data engineering and analytics by bringing software development practices to data pipelines. It enables rapid iteration, maintains data quality, and improves collaboration between technical and business teams. For organizations serious about business intelligence, dbt represents a significant advantage in building reliable, scalable data infrastructure.
visualize
report
interface
Often we need to subset the data or run different types of queries
query engine
SQL
elastic
agentic
Use an LLM to filter the data