WeightedAverage). Optionally, the calculation can be performed per group by selecting one or more grouping fields.
In Prophecy, the same logic is implemented using either a Reformat gem (when no grouping is present) or an Aggregate gem (when grouping is present).
Automated migration results
When Import detects an Alteryx Weighted Average tool, it applies one of two patterns:- No grouping fields configured: Import generates a Reformat gem that computes a single weighted average across the entire dataset.
- Grouping fields configured: Import generates an Aggregate gem with the selected grouping fields under Group by and a computed weighted-average expression.
Manually replicate in Prophecy
No grouping (overall weighted average)
- Add a Reformat gem.
- Add a new target column (for example,
WeightedAverage). - Configure the column to use a
case...when...elseexpression withwhensumofUnitsequals0, thennull.elsesum((UnitCost * Units)) / sum(Units)
With grouping (weighted average per group)
- Add an Aggregate gem.
- Add the grouping field(s) under Group by.
- Add a computed output column (for example,
WeightedAverage) using the samecase...when...elseexpression:
whensumofUnitsequals0, thennull.elsesum((UnitCost * Units)) / sum(Units)
Configuration options
Alteryx tool
- Select value field: Numeric field to be averaged (for example,
UnitCost). - Select weight field: Numeric field used as the weight (for example,
Units). - Select output field name: Name of the new weighted-average output field (for example,
WeightedAverage). - Select Grouping fields (optional): One or more fields used to compute a weighted average per group.
Prophecy gems
Reformat gem (no grouping)
- Create a new target column for the weighted average.
- Define an expression of the form
sum(value * weight) / sum(weight). - Include a divide-by-zero guard (
CASE WHEN sum(weight) = 0 THEN NULL) to match expected behavior.
Aggregate gem (grouping enabled)
- Add grouping fields under Group by.
- Define a computed output column using the same guarded weighted-average expression.
Output behavior
Alteryx produces a new output field containing the weighted average, either as a single value (no grouping) or one value per group. Prophecy produces:- A single-row result when implemented with a Reformat gem (no grouping), or
- One row per group when implemented with an Aggregate gem.
(value × weight) divided by the sum of weight.
Known caveats
- Zero or null weights: If the sum of weights is zero, the expression must guard against division by zero. Returning
NULLmatches the typical “no meaningful weighted average” case. - Null handling: Behavior depends on how null values are treated in the expression. If needed, normalize or filter inputs upstream to match Alteryx expectations.
- Numeric types: If value and weight fields are integers, consider casting to a decimal type to avoid unintended integer division.
Example
Alteryx (Weighted Average tool)
Goal: Compute a weighted average of unit cost using units as weights, optionally producing one result per region.- Input data: contains
UnitCost,Units, and optionallyRegion - Value field:
UnitCost - Weight field:
Units - Output field name:
WeightedAverage - Behavior:
- Multiply each
UnitCostby its correspondingUnits - Sum the weighted values
- Divide by the sum of
Units - If the sum of
Unitsis zero, returnNULL - If a grouping field (
Region) is selected, compute the weighted average separately for each region
- Multiply each
Prophecy (Reformat or Aggregate gems)
No grouping (Reformat)
-
Connect the input dataset containing
UnitCostandUnits. - Add a Reformat gem.
-
Add
WeightedAverageas a Target Column. -
Define the target column using the following expression:
This expression reproduces Alteryx’s weighted-average calculation across the full dataset while guarding against division by zero.
With grouping (Aggregate)
-
Connect the input dataset containing
UnitCost,Units, andRegion. - Add an Aggregate gem.
-
Configure Group by to include
Region. -
Add
WeightedAverageas a computed output column using the same expression:

