Skip to main content
PYSPARK โ€ข LESSON 283

Scenario: Daily Financial Revenue Reconciliation

How can we reconcile gateway processing fees, gross sales, refunds, and net revenue across payment providers daily?

Productionโฑ 3 Minutesโญ 820 XP
๐Ÿค” THE QUESTION

How can we reconcile gateway processing fees, gross sales, refunds, and net revenue across payment providers daily?

๐Ÿ’ก WHAT IS IT?

Conditional sum() aggregations by date and provider calculate financial balances and flag reconciliation discrepancies.

๐ŸŽฏ WHAT IS IT USED FOR?

Automated accounting pipelines verifying that bank deposits match internal ledger records exactly.

๐Ÿ’ป EXAMPLE
df_recon = df_ledger.groupBy("transaction_date", "payment_provider").agg(sum(when(col("type") == "SALE", col("amount")).otherwise(0)).alias("gross_sales"), sum(when(col("type") == "REFUND", col("amount")).otherwise(0)).alias("total_refunds"), sum("processing_fee").alias("total_fees")).withColumn("net_revenue", col("gross_sales") - col("total_refunds") - col("total_fees"))

๐ŸŽฏ Mission Objectives

Practice typing production-grade PySpark code for Scenario: Daily Financial Revenue Reconciliation.

  • โœ“ Financial ledger reconciliation
  • โœ“ Conditional fee and refund math
  • โœ“ Net revenue balance check