$compute
The $compute query option adds computed properties to each entity in the response.
Syntax
GET /odata/Products?$compute=price mul 1.1 as taxedPriceMultiple computed properties are comma-separated:
GET /odata/Products?$compute=concat(firstName,' ',lastName) as fullName,price mul qty as totalEach expression follows the pattern: expression as alias.
Supported expressions
String functions
| Function | Example | Result |
|---|---|---|
concat(a, b) | concat(first,' ',last) | Concatenation |
tolower(expr) | tolower(name) | Lowercase |
toupper(expr) | toupper(code) | Uppercase |
Arithmetic
| Operator | Example | Result |
|---|---|---|
add | price add 5 | Addition |
sub | price sub discount | Subtraction |
mul | price mul quantity | Multiplication |
div | total div count | Division (returns null if divisor is 0) |
Date functions
| Function | Example | Result |
|---|---|---|
year(prop) | year(createdAt) | Year as integer |
month(prop) | month(createdAt) | Month as integer |
day(prop) | day(createdAt) | Day as integer |
Literals
| Type | Example |
|---|---|
| String | 'hello' |
| Integer | 42 |
| Float | 3.14 |
Property references
Any declared property name can be used directly, a computed property of a discovered model included:
price mul 1.1 as taxedA name the entity type does not declare answers 400 with code unknown_property (Unknown property in $compute: …), as it does in $filter. The expression is checked with the $filter grammar before anything runs. changed in 4.0The expression used to be checked against nothing and could read any column the row held, declared or not.
Evaluation
Computed properties are evaluated in PHP after the row is fetched from the database, not at the SQL level. When $compute is present, the resolver skips SQL-level $select so all columns are available for computation. The engine applies response-level projection afterward.
Interaction with $select
Computed properties are always part of the response, whatever $select names. $select accepts only declared properties, so list the declared ones you want and leave the alias out:
GET /odata/Products?$compute=price mul 1.1 as taxed&$select=nameThis returns name and the computed taxed property. Naming taxed in $select answers 400 with code unknown_property.