Byte.From
NumberConverts a value to an 8-bit unsigned integer (0 to 255).
Syntax
Byte.From(value as any, optional culture as nullable text, optional roundingMode as nullable number) as nullable numberParameters
| Name | Type | Required | Description |
|---|---|---|---|
value | any | Yes | The value to convert. Accepts number, text, logical, or null. |
culture | text | No | An optional culture string for locale-aware parsing of text values (e.g., "en-US"). |
roundingMode | number | No | An optional rounding mode constant (e.g., RoundingMode.AwayFromZero) used when truncating fractional values. |
Return Value
number — An 8-bit unsigned integer in the range 0–255.
Remarks
Byte.From converts a value to a byte — an 8-bit unsigned integer spanning the range 0 to 255. This is distinct from Int8.From, which produces a signed 8-bit integer covering -128 to 127. Values outside the 0–255 range raise an error at runtime, so validate or clamp inputs before calling this function when working with untrusted data.
Fractional numbers are rounded before conversion. By default the function uses round-half-to-even (banker's rounding), which differs from the conventional "round half up" behavior. If you need traditional rounding — for example, 2.5 → 3 — pass RoundingMode.AwayFromZero as the third argument. Text values are parsed as decimal numbers first. A logical true converts to 1, false to 0, and null returns null.
The byte type is most commonly encountered when working with binary data streams, raw byte buffers, or low-level protocol fields. In most Power Query data transformation work you will use Int64.From (Whole Number) or Decimal.From instead. Use Byte.From explicitly when a downstream system requires values annotated with the 8-bit unsigned type — for example, when building typed table schemas for custom connectors that interface with byte-array columns.
To apply the byte type across an entire table column, use Table.TransformColumnTypes with Byte.Type.
Examples
Example 1: Convert an integer within range
Byte.From(200)Result | |
|---|---|
| 1 | 200 |
Example 2: Parse a text string as a byte
Byte.From("128")Result | |
|---|---|
| 1 | 128 |
Example 3: Rounding behavior — default vs. away-from-zero
#table(
{"Input", "Default (Banker's)", "AwayFromZero"},
{
{10.5, Byte.From(10.5), Byte.From(10.5, null, RoundingMode.AwayFromZero)},
{11.5, Byte.From(11.5), Byte.From(11.5, null, RoundingMode.AwayFromZero)}
}
)Input | Default (Banker's) | AwayFromZero | |
|---|---|---|---|
| 1 | 10.50 | 10 | 11 |
| 2 | 11.50 | 12 | 12 |