---
title: Units and parameters
summary: Convert units per column with UNIT or per statement with USING, write unit literals in conditions, and bind values at run time with $parameters.
order: 60
languages: [javascript]
terms: [bql, quantity]
see-also: [tutorials/bql/grouping-and-aggregates, reference/bql/unit, reference/bql/using, how-to/query/use-query-parameters]
---

# Units and parameters

Quantities have units, and models disagree about them: the demo model stores lengths in millimetres and areas in square metres, the next model may be in metres and feet. BQL lets you say which unit you want, in the result and in the condition, and leaves the conversion to the server.

## USING for the whole statement

`USING`, the last clause of a statement, sets the unit of every value of that dimension in the result:

```bql {#using-volume}
GET qid, attribute.Name, quantity.*.Height, quantity.*.Length WHERE type = IFCWALL USING LENGTH_UNIT = m
```

The value in the result is in metres, whatever the model stored, and the row says both: `value` and `unit` are what you asked for, `original_value` and `original_unit` what the file had — `0.51` m next to `510` mm. A value that is already in the target unit comes back unchanged and without the `original_*` fields, which is why converting the volumes of this model to `m3` changes nothing: the file already stores them in cubic metres. The clauses are `LENGTH_UNIT`, `AREA_UNIT`, `VOLUME_UNIT`, `MASS_UNIT` and `TEMPERATURE_UNIT`, in any order, each at most once: `USING LENGTH_UNIT = m AREA_UNIT = m2`.

## UNIT on a column

`UNIT` after a single `GET` item converts that column and ignores `USING` for it:

```bql {#unit}
GET qid, attribute.Name, calculated.quantity.volume UNIT m3 WHERE type = IFCWALL
```

`UNIT` belongs to a single feature; an aggregate cannot carry it (`SUM(x) UNIT m3` is a syntax error) — convert the whole result with `USING` instead. It works on any numeric value: `quantity.*.NetVolume UNIT m3` and `aabb.height UNIT m` convert an exported quantity and a bounding-box side the same way.

## USING with aggregates

`USING` also converts what an aggregate computed, which is the only way to choose the unit of a `SUM` or an `AVG`:

```bql {#using}
GET typeObject.attribute.Name, SUM(quantity.*.NetVolume) AS Volume
WHERE type = IFCWALL GROUP BY typeObject.attribute.Name
USING VOLUME_UNIT = m3
```

Use `UNIT` for one column and `USING` for the statement rather than both on the same value. The units are listed in [[bql:unit]] and [[bql:using]].

```warning
`UNIT`, `USING` and the unit literals in conditions take every unit of the grammar, imperial units and litres included ([[bql:using#units]]).
```

## Units in conditions

A numeric literal in `WHERE` takes a unit too, and the comparison converts before it compares. `quantity.*.Height BETWEEN 2 m AND 3 m` and `quantity.*.Height BETWEEN 2000 mm AND 3000 mm` select the same walls. Both sides of a comparison may be expressions: `quantity.*.NetVolume > calculated.quantity.volume * 1.1` compares two features, units resolved on both sides. Give a literal its unit: a number without one is compared as it is, without conversion ([[bql:unit#literals]]).

## Parameters

A `$name` may stand in for any literal: `= $x`, `> $min`, `IN $values`, `type IN $types`, `qid IN $selection`, `BETWEEN $low AND $high`. The value is supplied when the query runs, by the parameter panel of a stored query in the app, or by the `parameters` object of the query call in the JavaScript SDK and the Java request API:

```bql {#parameters}
GET qid, attribute.Name WHERE type IN $types AND attribute.Name CONTAINS $text
```

```example
name: query-with-parameters
code: javascript/query-with-parameters.js
run: none
notes: |
  The parameters object maps names to values: a list of class names for `type IN $types`, a string for `CONTAINS $text`. The same query runs with different values without being edited, and the values are never spliced into the text, so a user-supplied string cannot change the query. [[page:how-to/query/use-query-parameters]] shows the Java form; the .NET SDK, the PHP client and the HTTP [[openapi:Query]] operation have no `parameters` field yet.
highlight: 4-8
```

A query with an unbound parameter is valid but matches nothing for that condition, so a parameter is only useful together with the values: the last round of this lesson declares `$text` and the page binds it before it runs your query.

## Your turn

```lesson {#lesson-1}
goal: List every wall with its name, its height and its length, both lengths in metres.
show: json
check: values
starter: |
  GET qid, attribute.Name, quantity.*.Height, quantity.*.Length WHERE type = IFCWALL
hints: |
  - USING is the last clause of the statement.
  - Both quantities are lengths, so one LENGTH_UNIT clause covers them.
  - The model stores millimetres, so the numbers have to change.
solution: |
  GET qid, attribute.Name, quantity.*.Height, quantity.*.Length WHERE type = IFCWALL USING LENGTH_UNIT = m
accept: |
  - GET attribute.Name, qid, quantity.*.Length, quantity.*.Height WHERE type = IFCWALL USING LENGTH_UNIT = m
```

Read one converted leaf in the JSON: `value` and `unit` are the metres you asked for, `original_value` and `original_unit` the millimetres the file stored.

```lesson {#lesson-2}
goal: List every wall with its name and the volume BIM.works computes from its geometry, in cubic metres, converted on the column itself rather than with USING.
show: table
check: values
require: \bUNIT\b
require-message: this round is about UNIT on one GET item; USING converts the whole statement instead
starter: |
  GET qid, attribute.Name, calculated.quantity.volume WHERE type = IFCWALL
hints: |
  - UNIT follows the GET item it converts.
  - The unit for cubic metres is m3.
solution: |
  GET qid, attribute.Name, calculated.quantity.volume UNIT m3 WHERE type = IFCWALL
accept: |
  - GET qid, calculated.quantity.volume UNIT m3, attribute.Name WHERE type = IFCWALL
```

```lesson {#lesson-3}
goal: List the walls between 2 and 3 metres high, with their height in metres.
show: table
check: values
starter: |
  GET qid, attribute.Name, quantity.*.Height WHERE type = IFCWALL
hints: |
  - BETWEEN takes two bounds joined by AND, and each bound may carry a unit.
  - The model stores millimetres, so the result needs a conversion of its own.
solution: |
  GET qid, attribute.Name, quantity.*.Height WHERE type = IFCWALL AND quantity.*.Height BETWEEN 2 m AND 3 m USING LENGTH_UNIT = m
accept: |
  - GET qid, attribute.Name, quantity.*.Height WHERE type = IFCWALL AND quantity.*.Height BETWEEN 2000 mm AND 3000 mm USING LENGTH_UNIT = m
  - GET qid, attribute.Name, quantity.*.Height WHERE type = IFCWALL AND quantity.*.Height >= 2 m AND quantity.*.Height <= 3 m USING LENGTH_UNIT = m
```

```lesson {#lesson-4}
goal: List the spaces whose LongName contains a word supplied at run time, with their name and LongName — this round binds `$text` to "kamer" (room).
show: table
check: values
params: {"text": "kamer"}
require: \$text
require-message: the word has to come from the parameter $text, not from a literal in the query
starter: |
  GET qid, attribute.Name, attribute.LongName WHERE type = IFCSPACE AND attribute.LongName CONTAINS "kamer"
hints: |
  - A parameter is a $ followed by its name, in the place of the literal.
  - The name matters: this round binds $text.
  - Nothing else about the query changes.
solution: |
  GET qid, attribute.Name, attribute.LongName WHERE type = IFCSPACE AND attribute.LongName CONTAINS $text
accept: |
  - GET qid, attribute.LongName, attribute.Name WHERE type = IFCSPACE AND attribute.LongName CONTAINS $text
```

Every round of this course binds the parameters it declares, so `$text` arrives with a value. In your own code the values travel next to the query — `client.bim.query(models, query, false, false, {text: "kamer"})` in JavaScript — and are inserted into the parsed query, never into its text, so a value from a user can never change what the query does.

```note
A parameter name may not be a word the grammar uses: `$name` and `$level` are syntax errors, `$text` and `$storey` are fine. A parameter behind a relation (`buildingStorey.attribute.Name = $storey`) binds like any other.
```

## You can now

- Convert one column with `UNIT` and a whole result with `USING`.
- Write conditions with unit literals and compare features with each other.
- Parameterise a query with `$name` and bind the values from an SDK.

Next: [Calculated values](calculated-values.md), the quantities BIM.works works out from the geometry itself.
