> ## Documentation Index
> Fetch the complete documentation index at: https://doc.lucidworks.com/llms.txt
> Use this file to discover all available pages before exploring further.

# weighted_sum

[localhost link]: http://localhost:3000/docs/4/fusion-server/reference/fusion-sql/weighted_sum

[mintlify link]: https://doc.lucidworks.com/docs/4/fusion-server/reference/fusion-sql/weighted_sum

[old doc.lw link]: https://doc.lucidworks.com/fusion-server/4.2/3263

The `weighted_sum` UDAF takes a weight, type, and type-weight mapping to produce an aggregated weight. For example, consider the following SQL snippet:
import { LwTemplate } from '/snippets/LwTemplate.jsx';

<LwTemplate />

```sql theme={"dark"}
    SELECT query,
          doc_id,
          filters,
          weighted_sum(typed_weight_d, type, 'click:1.0,cart:10.0') AS weight_d
     FROM signal_type_groups
 GROUP BY query, doc_id, filters
```

When applied to the rows in the table below, the `weighted_sum` function produces a final `weight_d` of 12.0 (2*1.0 + 1*10.0). The UDAF is passed rows grouped by `query`, `doc_id`, and `filters`.

| `query` | `type`  | `doc_id` | `filters` | `typed_weight_d` |
| ------- | ------- | -------- | --------- | ---------------- |
| `iPad`  | `click` | `1`      | `gear`    | `2`              |
| `iPad`  | `cart`  | `1`      | `gear`    | `1`              |
