Byte.From

Updated on

Byte.From is a Power Query M function that returns an 8-bit integer number value from a given value. It handles null, numbers within the 8-bit integer range, and other types by converting them to numbers using Number.FromText. An optional culture parameter can be provided.

Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365

Syntax

Byte.From(
   value as any,
   optional culture as nullable text,
   optional roundingMode as nullable number,
) as nullable number
Argument Attribute Description
value
culture optional The culture argument enables the specification of a Culture code (e.g., “nl-NL” or “en-US”) to align transformations with local formatting conventions. If this argument is omitted, functions default to Culture.Current, which reflects the system’s regional settings.
roundingMode optional The RoundingMode.Type argument controls the rounding method applied. When omitted, the function uses RoundingMode.ToEven, which rounds to the nearest even number in tie situations. Other options include:
RoundingMode.Up rounds up in such cases.
RoundingMode.Down rounds down.
RoundingMode.TowardZero rounds toward zero.
RoundingMode.AwayFromZero rounds away from zero.

Description

Returns an 8-bit integer number value from the given value. If the given value is null, Byte.From returns null. If the given value is a number within the range of an 8-bit integer without a fractional part, value is returned. If it has fractional part, then the number is rounded with the rounding mode specified. The default rounding mode is RoundingMode.ToEven. If value is of any other type, it will first be converted to a number using Number.FromText. Refer to Number.Round for the available rounding modes. An optional culture may also be provided (for example, “en-US”).

Examples

Get the 8-bit integer number value of "4".

// Output: 4
Byte.From( "4" )

Get the 8-bit integer number value of "4.5" using RoundingMode.AwayFromZero.

// Output: 5
Byte.From( "4.5", null, RoundingMode.AwayFromZero )

Other functions related to Byte.From are:

Contribute » | Contributors: Rick de Groot
Microsoft documentation: https://learn.microsoft.com/en-us/powerquery-m/byte-from