๐Ÿ“Š Data Engineering

BI

Business Intelligence

Analyzing data to support business decision-making. Tableau and Power BI are representative tools.

Detailed Explanation

Business Intelligence (BI) is the collective term for the technologies, processes, and tools that collect, store, and analyze an organization's data and turn it into insights that can be used for decision-making. It uses past data to understand the current situation (Descriptive), analyzes why things happened (Diagnostic), and predicts the future (Predictive).

The core of modern BI is self-service BI. In the past, only the IT department or data specialists performed analysis, but now business users can explore and visualize data themselves. Tools such as Tableau, Power BI, Looker, and Metabase simplify complex analysis with drag-and-drop interfaces.

Data infrastructure is essential for effective BI implementation. Data is collected through ETL/ELT pipelines, stored in a data warehouse (BigQuery, Snowflake, Redshift), and given an analysis-optimized structure through data modeling (Star Schema, Snowflake Schema). The Semantic Layer connects business terms with technical data to provide consistent metric definitions.

BI is evolving toward Embedded Analytics and Augmented Analytics. Embedded Analytics builds BI capabilities into your own application so users get insights without a separate tool. Augmented Analytics uses AI/ML to automatically detect anomalies, query data with natural-language questions, and recommend insights.

Code Example

# BI ๋Œ€์‹œ๋ณด๋“œ ์„ค๊ณ„ ์›์น™ ๋ฐ ๊ตฌํ˜„ ์˜ˆ์ œ

# ============================================
# 1. ํšจ๊ณผ์ ์ธ ๋Œ€์‹œ๋ณด๋“œ ์„ค๊ณ„ ์›์น™
# ============================================

"""
[๋Œ€์‹œ๋ณด๋“œ ์„ค๊ณ„ 5์›์น™]

1. ๋ชฉ์  ๋ช…ํ™•ํ™” (Purpose)
   - ๋ˆ„๊ฐ€ ์‚ฌ์šฉํ•˜๋‚˜? (๊ฒฝ์˜์ง„, ์šด์˜ํŒ€, ๋ถ„์„๊ฐ€)
   - ์–ด๋–ค ์งˆ๋ฌธ์— ๋‹ตํ•ด์•ผ ํ•˜๋‚˜?
   - ์–ด๋–ค ํ–‰๋™์„ ์œ ๋„ํ•˜๋‚˜?

2. ์ •๋ณด ๊ณ„์ธตํ™” (Hierarchy)
   - ๊ฐ€์žฅ ์ค‘์š”ํ•œ ์ง€ํ‘œ๋ฅผ ์ƒ๋‹จ/์ขŒ์ธก์— ๋ฐฐ์น˜
   - ์š”์•ฝ โ†’ ์ƒ์„ธ ์ˆœ์„œ๋กœ ๋“œ๋ฆด๋‹ค์šด
   - 3์ดˆ ๋‚ด ํ•ต์‹ฌ ๋ฉ”์‹œ์ง€ ์ „๋‹ฌ

3. ์‹œ๊ฐํ™” ์„ ํƒ (Visualization)
   - ๋น„๊ต: ๋ง‰๋Œ€ ์ฐจํŠธ
   - ์ถ”์„ธ: ๋ผ์ธ ์ฐจํŠธ
   - ๊ตฌ์„ฑ: ํŒŒ์ด/๋„๋„› ์ฐจํŠธ
   - ๋ถ„ํฌ: ํžˆ์Šคํ† ๊ทธ๋žจ/๋ฐ•์Šคํ”Œ๋กฏ
   - ๊ด€๊ณ„: ์‚ฐ์ ๋„

4. ์ธํ„ฐ๋ž™ํ‹ฐ๋ธŒ (Interactive)
   - ํ•„ํ„ฐ๋กœ ์„ธ๊ทธ๋จผํŠธ ํƒ์ƒ‰
   - ๋“œ๋ฆด๋‹ค์šด์œผ๋กœ ์ƒ์„ธ ๋ถ„์„
   - ํˆดํŒ์œผ๋กœ ์ถ”๊ฐ€ ์ •๋ณด ์ œ๊ณต

5. ์„ฑ๋Šฅ ์ตœ์ ํ™” (Performance)
   - ์‚ฌ์ „ ์ง‘๊ณ„๋œ ๋ฐ์ดํ„ฐ ์‚ฌ์šฉ
   - ์ฆ๋ถ„ ๋กœ๋”ฉ ๊ตฌํ˜„
   - ์บ์‹ฑ ์ „๋žต ์ˆ˜๋ฆฝ
"""

# ============================================
# 2. Semantic Layer ์ •์˜ (dbt Metrics)
# ============================================

# models/metrics/revenue_metrics.yml
"""
version: 2

metrics:
  - name: total_revenue
    label: Total Revenue
    model: ref('fct_orders')
    description: "์ด ๋งค์ถœ์•ก"
    calculation_method: sum
    expression: order_amount
    timestamp: order_date
    time_grains: [day, week, month, quarter, year]
    dimensions:
      - product_category
      - region
      - channel
    filters:
      - field: order_status
        operator: '='
        value: "'completed'"

  - name: average_order_value
    label: Average Order Value
    model: ref('fct_orders')
    description: "ํ‰๊ท  ์ฃผ๋ฌธ ๊ธˆ์•ก"
    calculation_method: average
    expression: order_amount
    timestamp: order_date
    time_grains: [day, week, month]
    dimensions:
      - product_category
      - customer_segment

  - name: conversion_rate
    label: Conversion Rate
    model: ref('fct_user_events')
    description: "๊ตฌ๋งค ์ „ํ™˜์œจ"
    calculation_method: derived
    expression: "{{metric('purchases')}} / {{metric('page_views')}}"
    timestamp: event_date
    time_grains: [day, week, month]
"""

# ============================================
# 3. Python์œผ๋กœ ๋Œ€์‹œ๋ณด๋“œ ๋ฐ์ดํ„ฐ ์ค€๋น„
# ============================================
import pandas as pd
import numpy as np
from datetime import datetime, timedelta

def prepare_executive_dashboard_data(conn):
    """๊ฒฝ์˜์ง„ ๋Œ€์‹œ๋ณด๋“œ์šฉ ๋ฐ์ดํ„ฐ ์ค€๋น„"""

    # ํ•ต์‹ฌ KPI ์ง‘๊ณ„
    kpi_query = """
    WITH current_period AS (
        SELECT
            SUM(revenue) as total_revenue,
            COUNT(DISTINCT customer_id) as unique_customers,
            COUNT(*) as total_orders,
            SUM(revenue) / COUNT(*) as aov
        FROM orders
        WHERE order_date >= DATE_TRUNC('month', CURRENT_DATE)
    ),
    previous_period AS (
        SELECT
            SUM(revenue) as total_revenue,
            COUNT(DISTINCT customer_id) as unique_customers,
            COUNT(*) as total_orders,
            SUM(revenue) / COUNT(*) as aov
        FROM orders
        WHERE order_date >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '1 month')
          AND order_date < DATE_TRUNC('month', CURRENT_DATE)
    )
    SELECT
        c.total_revenue,
        c.unique_customers,
        c.total_orders,
        c.aov,
        (c.total_revenue - p.total_revenue) / p.total_revenue * 100 as revenue_growth,
        (c.unique_customers - p.unique_customers) / p.unique_customers * 100 as customer_growth
    FROM current_period c, previous_period p
    """

    kpis = pd.read_sql(kpi_query, conn)

    # ์ผ๋ณ„ ํŠธ๋ Œ๋“œ
    trend_query = """
    SELECT
        DATE(order_date) as date,
        SUM(revenue) as daily_revenue,
        COUNT(*) as daily_orders,
        COUNT(DISTINCT customer_id) as daily_customers
    FROM orders
    WHERE order_date >= CURRENT_DATE - INTERVAL '30 days'
    GROUP BY DATE(order_date)
    ORDER BY date
    """

    trends = pd.read_sql(trend_query, conn)

    # ์นดํ…Œ๊ณ ๋ฆฌ๋ณ„ ๋ถ„ํฌ
    category_query = """
    SELECT
        product_category,
        SUM(revenue) as revenue,
        COUNT(*) as orders,
        SUM(revenue) / SUM(SUM(revenue)) OVER() * 100 as revenue_share
    FROM orders o
    JOIN products p ON o.product_id = p.product_id
    WHERE order_date >= DATE_TRUNC('month', CURRENT_DATE)
    GROUP BY product_category
    ORDER BY revenue DESC
    """

    categories = pd.read_sql(category_query, conn)

    return {
        'kpis': kpis.to_dict('records')[0],
        'trends': trends.to_dict('records'),
        'categories': categories.to_dict('records')
    }

# ============================================
# 4. Looker LookML ์˜ˆ์ œ
# ============================================
"""
# views/orders.view.lkml
view: orders {
  sql_table_name: `project.dataset.orders` ;;

  dimension: order_id {
    primary_key: yes
    type: string
    sql: ${TABLE}.order_id ;;
  }

  dimension_group: order {
    type: time
    timeframes: [raw, date, week, month, quarter, year]
    sql: ${TABLE}.order_date ;;
  }

  dimension: customer_id {
    type: string
    sql: ${TABLE}.customer_id ;;
  }

  dimension: revenue {
    type: number
    sql: ${TABLE}.revenue ;;
    value_format_name: usd
  }

  dimension: revenue_tier {
    type: tier
    tiers: [0, 50, 100, 500, 1000]
    style: integer
    sql: ${revenue} ;;
  }

  measure: total_revenue {
    type: sum
    sql: ${revenue} ;;
    value_format_name: usd_0
    drill_fields: [order_id, customer_id, revenue]
  }

  measure: average_order_value {
    type: average
    sql: ${revenue} ;;
    value_format_name: usd
  }

  measure: order_count {
    type: count_distinct
    sql: ${order_id} ;;
  }

  measure: customer_count {
    type: count_distinct
    sql: ${customer_id} ;;
  }
}

# explores/orders.explore.lkml
explore: orders {
  label: "Orders Analysis"
  description: "์ฃผ๋ฌธ ๋ฐ์ดํ„ฐ ๋ถ„์„"

  join: customers {
    type: left_outer
    sql_on: ${orders.customer_id} = ${customers.customer_id} ;;
    relationship: many_to_one
  }

  join: products {
    type: left_outer
    sql_on: ${orders.product_id} = ${products.product_id} ;;
    relationship: many_to_one
  }
}
"""

# ============================================
# 5. Tableau Prep ๋ฐ์ดํ„ฐ ์ค€๋น„ (Python ๋Œ€์•ˆ)
# ============================================
def prepare_tableau_extract(source_df):
    """Tableau์šฉ ๋ฐ์ดํ„ฐ ์ถ”์ถœ ์ค€๋น„"""

    df = source_df.copy()

    # ๋‚ ์งœ ํ•„๋“œ ํŒŒ์‹ฑ
    df['order_date'] = pd.to_datetime(df['order_date'])
    df['order_year'] = df['order_date'].dt.year
    df['order_month'] = df['order_date'].dt.month
    df['order_week'] = df['order_date'].dt.isocalendar().week
    df['order_day_of_week'] = df['order_date'].dt.day_name()

    # ๊ณ„์‚ฐ ํ•„๋“œ ์ถ”๊ฐ€
    df['revenue_per_item'] = df['revenue'] / df['quantity']
    df['is_high_value'] = df['revenue'] > df['revenue'].quantile(0.75)

    # ์„ธ๊ทธ๋จผํŠธ ์ƒ์„ฑ
    df['customer_segment'] = pd.cut(
        df.groupby('customer_id')['revenue'].transform('sum'),
        bins=[0, 100, 500, 1000, float('inf')],
        labels=['Bronze', 'Silver', 'Gold', 'Platinum']
    )

    # ์ด์ƒ์น˜ ํ”Œ๋ž˜๊ทธ
    df['is_outlier'] = (
        (df['revenue'] < df['revenue'].quantile(0.01)) |
        (df['revenue'] > df['revenue'].quantile(0.99))
    )

    return df

# ============================================
# 6. Embedded Analytics API ์˜ˆ์ œ
# ============================================
import requests
import jwt
from datetime import datetime, timedelta

class EmbeddedBIClient:
    """Embedded BI ํด๋ผ์ด์–ธํŠธ (Looker ์Šคํƒ€์ผ)"""

    def __init__(self, base_url, client_id, client_secret):
        self.base_url = base_url
        self.client_id = client_id
        self.client_secret = client_secret
        self.access_token = None

    def authenticate(self):
        """OAuth2 ์ธ์ฆ"""
        response = requests.post(
            f"{self.base_url}/api/4.0/login",
            data={
                'client_id': self.client_id,
                'client_secret': self.client_secret
            }
        )
        self.access_token = response.json()['access_token']

    def create_embed_url(self, dashboard_id, user_attributes, embed_domain):
        """SSO Embed URL ์ƒ์„ฑ"""
        embed_params = {
            'resource': {'dashboard': dashboard_id},
            'user': {
                'first_name': user_attributes.get('first_name', 'User'),
                'last_name': user_attributes.get('last_name', ''),
                'permissions': ['access_data', 'see_user_dashboards'],
                'models': ['orders'],
                'user_attributes': {
                    'company_id': user_attributes.get('company_id'),
                    'region': user_attributes.get('region')
                }
            },
            'embed_domain': embed_domain,
            'session_length': 3600,
            'force_logout_login': True
        }

        # JWT ํ† ํฐ ์ƒ์„ฑ
        token = jwt.encode(
            {
                **embed_params,
                'exp': datetime.utcnow() + timedelta(hours=1)
            },
            self.client_secret,
            algorithm='HS256'
        )

        return f"{self.base_url}/embed/dashboards/{dashboard_id}?embed_token={token}"

    def run_query(self, model, view, fields, filters=None, sorts=None, limit=500):
        """์ฟผ๋ฆฌ ์‹คํ–‰"""
        query_body = {
            'model': model,
            'view': view,
            'fields': fields,
            'filters': filters or {},
            'sorts': sorts or [],
            'limit': limit
        }

        response = requests.post(
            f"{self.base_url}/api/4.0/queries/run/json",
            headers={'Authorization': f'Bearer {self.access_token}'},
            json=query_body
        )

        return response.json()

# ์‚ฌ์šฉ ์˜ˆ์ œ
"""
client = EmbeddedBIClient(
    base_url='https://your-looker-instance.com',
    client_id='your_client_id',
    client_secret='your_client_secret'
)

client.authenticate()

# ๋Œ€์‹œ๋ณด๋“œ ์ž„๋ฒ ๋“œ URL ์ƒ์„ฑ
embed_url = client.create_embed_url(
    dashboard_id='sales_overview',
    user_attributes={
        'company_id': 'ACME',
        'region': 'APAC'
    },
    embed_domain='https://your-app.com'
)
"""

print("BI ๋Œ€์‹œ๋ณด๋“œ ์„ค๊ณ„ ์˜ˆ์ œ ์™„๋ฃŒ")

How it is used in practice

Business analyst: "I'm creating the sales report manually every time. Can we automate it?"

Data engineer: "If you build a dashboard with Looker or Metabase, it updates in real time and you can also set up automatic email delivery. If you first list the metrics you look at often, I'll define them in the Semantic Layer."

Business analyst: "Each department looks at things differently, so even the same metric is sometimes defined differently."

Data engineer: "That's why the Semantic Layer matters. If you create standard metric definitions used company-wide and have every dashboard reference the same definitions, consistency is maintained."

Interviewer: "What principles do you consider most important in designing an effective BI dashboard?"

Candidate: "The most important thing is clarifying the purpose. An executive dashboard should show 3-5 key KPIs at a glance, while one for the operations team should focus on real-time monitoring and alerts. Information hierarchy is also important: put the most important metric in the top left and allow detailed analysis through drill-down. Finally, performance. However good a dashboard is, people stop using it if it takes more than 5 seconds to load, so pre-aggregation and caching strategies are essential."

Take a mock interview on this topic โ†’ WIA SOOM AI Interview ยท Start for free

Reviewer: "The dashboard has as many as 15 metrics. That seems like too many."

Developer: "I included everything as users requested. Should I cut it down?"

Reviewer: "According to Miller's Law, people can process about 7 pieces of information at a time. It would be better to place 5 key KPIs large at the top and separate the rest into tabs or drill-downs. Also, combining similar metrics such as DAU and WAU into a single chart saves space and makes comparison easier."

Cautions

Related Terms

Learn More