Skip to main content
PYSPARK โ€ข LESSON 85

Multi-Dimensional Group Aggregation

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

Intermediateโฑ 2 Minutesโญ 420 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