# `Ash.Resource.Calculation`
[🔗](https://github.com/ash-project/ash/blob/v3.23.1/lib/ash/resource/calculation/calculation.ex#L5)

The behaviour for defining a module calculation, and the struct for storing a defined calculation.

# `opts`

```elixir
@type opts() :: Keyword.t()
```

# `ref`

```elixir
@type ref() :: {module(), Keyword.t()} | module()
```

# `t`

```elixir
@type t() :: %Ash.Resource.Calculation{
  __spark_metadata__: Spark.Dsl.Entity.spark_meta(),
  allow_nil?: boolean(),
  arguments: [Ash.Resource.Calculation.Argument.t()],
  async?: boolean(),
  calculation: module() | {module(), keyword()},
  constraints: keyword(),
  description: nil | String.t(),
  field?: boolean(),
  filterable?: boolean(),
  load: keyword(),
  multitenancy: nil | :enforce | :allow_global | :bypass | :bypass_all,
  name: atom(),
  public?: boolean(),
  sensitive?: boolean(),
  sortable?: boolean(),
  type: nil | Ash.Type.t()
}
```

# `calculate`
*optional* 

```elixir
@callback calculate(
  records :: [Ash.Resource.record()],
  opts :: opts(),
  context :: Ash.Resource.Calculation.Context.t()
) :: {:ok, [term()]} | [term()] | {:error, term()} | :unknown
```

# `describe`

```elixir
@callback describe(opts :: opts()) :: String.t()
```

# `expression`
*optional* 

```elixir
@callback expression(opts :: opts(), context :: Ash.Resource.Calculation.Context.t()) ::
  any()
```

# `has_expression?`

```elixir
@callback has_expression?() :: boolean()
```

# `init`

```elixir
@callback init(opts :: opts()) :: {:ok, opts()} | {:error, term()}
```

# `load`

```elixir
@callback load(
  query :: Ash.Query.t(),
  opts :: opts(),
  context :: Ash.Resource.Calculation.Context.t()
) ::
  atom() | [atom()] | Keyword.t()
```

A load statement to be applied when the calculation is used.
Only works with module-based or function-based calculations, not expression calculations.

# `strict_loads?`

```elixir
@callback strict_loads?() :: boolean()
```

# `schema`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
