pyspark.sql.functions.
sum_distinct
Aggregate function: returns the sum of distinct values in the expression.
New in version 3.2.0.
Changed in version 3.4.0: Supports Spark Connect.
Column
target column to compute on.
the column for computed results.
Examples
>>> df = spark.createDataFrame([(None,), (1,), (1,), (2,)], schema=["numbers"]) >>> df.select(sum_distinct(col("numbers"))).show() +---------------------+ |sum(DISTINCT numbers)| +---------------------+ | 3| +---------------------+