Skip to main content
PYSPARK • LESSON 74

Calculating Financial Totals with sum()

How do we compute total gross revenue across all transactions using the sum() function?

Intermediate2 Minutes360 XP
🤔 THE QUESTION

How do we compute total gross revenue across all transactions using the sum() function?

💡 WHAT IS IT?

sum() calculates the total numerical sum across all rows for a target Column.

🎯 WHAT IS IT USED FOR?

Executive financial reporting, revenue tracking, and batch volume monitoring.

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

df.select(sum(col("amount")).alias("total_revenue")).show()

🎯 Mission Objectives

Practice typing production-grade PySpark code for Calculating Financial Totals with sum().

  • Import sum function
  • Aggregate transaction amounts
  • Alias calculated total revenue