Data Warehousing and Data MiningUnit 46 min read
Data Cube: OLAP, Aggregation, Drill-Down & Slicing
Unit 4 of Data Warehousing and Data Mining explains data cubes, their structure, operations (roll-up, drill-down, slice/dice), and how they enable OLAP for fast analytics. Covers multidimensional modeling, aggregation hierarchies, and real-world applications in business intelligence.
What is a Data Cube?
A data cube is a multidimensional data structure that stores aggregated data for fast querying and analysis. Unlike flat tables, it organizes data along dimensions (e.g., time, product, region) and measures (e.g., sales, profit).
Key Components
- Facts: Quantitative data (e.g., sales amount, quantity).
- Dimensions: Qualitative attributes (e.g., date, product category, store location).
- Hierarchies: Levels within dimensions (e.g., Day → Month → Year).
- Cells: Intersection of dimensions and measures (e.g., "Sales of Product A in Kathmandu in Q1 2024").
graph LR
A["Data Cube"] --> B["Facts (Measures)"]
A --> C["Dimensions"]
C --> D["Time\n(Day→Month→Year)"]
C --> E["Product\n(Category→Brand→Model)"]
C --> F["Location\n(District→Region→Country)"]
B --> G["Sales Amount\nQuantity"]How Data Cubes Work: Multidimensional Modeling
A data cube is built using OLAP (Online Analytical Processing) techniques. It allows users to:
- View data from different angles (e.g., sales by product vs. sales by region).
- Aggregate data (sum, avg, count) at different levels (e.g., daily → monthly → yearly).
Example: Sales Data Cube
| Product | Region | Month | Sales (₹) |
|---|---|---|---|
| Laptop | Kathmandu | Jan 2024 | 5,000,000 |
| Mobile | Pokhara | Jan 2024 | 3,000,000 |
| Laptop | Kathmandu | Feb 2024 | 6,000,000 |
Dimensions:
- Product (Laptop, Mobile)
- Region (Kathmandu, Pokhara)
- Time (Jan, Feb)
Measure: Sales (₹)
OLAP Operations on Data Cubes
Data cubes support six key operations for analysis:
| Operation | Description | Example |
|---|---|---|
| Roll-Up | Aggregates data upward (e.g., day → month → year). | Sum sales for all products in Kathmandu for Q1 2024. |
| Drill-Down | Moves from high-level to detailed data (e.g., year → month → day). | Break down Q1 2024 sales into January, February, March. |
| Slice | Selects a 2D "slice" of the cube (fix one dimension). | Sales of Laptops across all regions in Jan 2024. |
| Dice | Selects a sub-cube (fix multiple dimensions). | Sales of Laptops in Kathmandu for Jan 2024. |
| Pivot | Rotates dimensions (e.g., swap rows and columns). | View sales by region vs. product (instead of product vs. region). |
| Drill-Across | Compares data across dimensions (e.g., sales vs. profit). | Compare laptop sales and profit margins in Kathmandu. |
Worked Example: Roll-Up and Drill-Down
Scenario: Daraz wants to analyze sales trends.
Step 1: Raw Data (Daily Sales)
| Date | Product | Region | Sales (₹) |
|---|---|---|---|
| 2024-01-01 | Laptop | Kathmandu | 500,000 |
| 2024-01-02 | Mobile | Pokhara | 300,000 |
| 2024-01-03 | Laptop | Kathmandu | 600,000 |
Step 2: Roll-Up (Daily → Monthly)
| Month | Product | Region | Total Sales (₹) |
|---|---|---|---|
| Jan 2024 | Laptop | Kathmandu | 1,100,000 |
| Jan 2024 | Mobile | Pokhara | 300,000 |
Step 3: Drill-Down (Monthly → Daily)
| Date | Product | Region | Sales (₹) |
|---|---|---|---|
| 2024-01-01 | Laptop | Kathmandu | 500,000 |
| 2024-01-03 | Laptop | Kathmandu | 600,000 |
Advantages and Disadvantages of Data Cubes
| Advantages | Disadvantages |
|---|---|
| ✅ Fast querying (pre-aggregated data) | ❌ Storage overhead (duplicates data) |
| ✅ Supports complex analysis (OLAP) | ❌ Slow updates (batch processing) |
| ✅ User-friendly (visual dashboards) | ❌ Not for real-time data |
| ✅ Scalable (handles large datasets) | ❌ Requires schema design |
In the Real World
eSewa (Nepal)
- Uses data cubes to analyze transaction trends (e.g., "How many users paid electricity bills in Kathmandu last month?").
- Operation: Slice → Filter by region (Kathmandu) and time (Jan 2024).
NTC (Nepal Telecom)
- Tracks call data records (CDRs) in a cube to detect fraud (e.g., "Which districts have the highest call volumes?").
- Operation: Roll-Up → Aggregate daily calls to monthly trends.
Google Analytics (Global)
- Uses data cubes to let marketers drill down into website traffic (e.g., "Which countries visited our site in Q1?").
- Operation: Drill-Down → From country → city → device type.
Exam Tip
- Focus on OLAP operations: Be able to apply roll-up, drill-down, slice, and dice on given datasets.
- Draw a data cube: In exams, sketch a cube with dimensions, hierarchies, and measures to explain concepts.
- Compare with flat tables: Highlight why cubes are better for analytics (speed, flexibility).
- Real-world mapping: Relate to eSewa, NTC, or Daraz in short-answer questions.
Visual: Data Cube Operations
graph LR
A["Data Cube\n(Sales Data)"] --> B["Roll-Up\n(Yearly Sales)"]
A --> C["Drill-Down\n(Daily Sales)"]
A --> D["Slice\n(Laptops Only)"]
A --> E["Dice\n(Kathmandu, Jan 2024)"]
B --> F["Total: ₹25M"]
C --> G["Day 1: ₹500K\nDay 2: ₹600K"]
D --> H["Laptop Sales: ₹10M"]
E --> I["₹1.1M"]IMAGE: OLAP Cube Visualization
OLAP data cube diagram | A labeled 3D cube showing dimensions (Time, Product, Region) and measures (Sales).
IMAGE: eSewa Dashboard (Example Output)
eSewa transaction analytics dashboard | A screenshot of a real dashboard showing monthly bill payments by district (Kathmandu, Pokhara, etc.).
Based on the TU BIT syllabus for Data Warehousing and Data Mining, unit 4.
Discussion
Loading…