Skip to main content
PYSPARK • LESSON 85

Multi-Dimensional Group Aggregation

How do we calculate category revenue within each individual retail store location?

Intermediate2 Minutes420 XP
🤔 THE QUESTION

How do we calculate category revenue within each individual retail store location?

💡 WHAT IS IT?

Grouping simultaneously across store_id and product_category to produce fine-grained category revenue sums.

🎯 WHAT IS IT USED FOR?

Store merchandising optimization, inventory allocation, and local demand forecasting.

💻 EXAMPLE
from pyspark.sql.functions import col, sum

df.groupBy("store_id", "product_category").agg(
    sum(col("revenue")).alias("category_revenue")
).show()

🎯 Mission Objectives

Practice typing production-grade PySpark code for Multi-Dimensional Group Aggregation.

  • Group by store and category
  • Aggregate store-level category revenue
  • Display multi-dimensional sales breakdown