Currency.From is a function in the Power Query M language that returns a currency value from the given value. If the value is null, the function returns null. If the value is within the range of currency, the fractional part of the value is rounded to 4 decimal digits and returned.
Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365
Syntax
Currency.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
The Currency.From function converts a given value into a currency value. If the input value is null
, it returns null
. If the value is a number within the currency range, it rounds any fractional part to 4 decimal places and returns it. For other types of input, the function first converts them to numbers using Number.FromText.
The valid range for currency values is from -922,337,203,685,477.5808 to 922,337,203,685,477.5807. The default rounding mode is RoundingMode.ToEven
, but other rounding modes are available as specified at RoundingMode.Type. You can also provide an optional culture parameter, like “en-US”, for locale-specific formatting.
Examples
Let’s look at some examples to understand the Currency.From function.
Converting a Text Number to Currency
Imagine you have the text “1.23455” and you want to convert it to a currency value. The function will round the fractional part to 4 decimal places using the default rounding mode, which is RoundingMode.ToEven
. So, “1.23455” gets rounded to “1.2346”.
// Output: 1.2346
Currency.From( "1.23455" )
Converting a Text Number with Specific Rounding
Let’s say you have the text “1.99857” and you want to round it using a different rounding mode. By using RoundingMode.Down
, the function will round down the value, so “1.99857” becomes “1.9986.
// Output: 1.9986
Currency.From( "1.99857", "en-US", RoundingMode.Down )
Handling Null Values
If the input value is null
, the function returns null
without any conversion.
// Output: null
Currency.From( null )
Converting a Number with Default Rounding
Now, imagine you have the number 1234.99499 and want to convert it to a currency value. By default, the function rounds the fractional part to 4 decimal places using RoundingMode.ToEven
, so 1234.99499 becomes 1234.995.
// Output: 1234.995
Currency.From( 1234.99499 )
Using an Optional Culture Parameter
You can also specify a culture parameter to handle locale-specific formatting. For example, converting “1234,5678” to a currency value using the “de-DE” culture, which uses commas as decimal separators.
// Output: 1234.5678
Currency.From( "1234,5678", "nl-NL" )
These examples show how the Currency.From
function can convert different types of input into properly formatted currency values, accommodating various rounding modes and cultural formats.
Related functions
Other functions related to Currency.From are:
- Byte.From
- Decimal.From
- Double.From
- Int16.From
- Int32.From
- Int64.From
- Int8.From
- Number.From
- Number.FromText
- Number.ToText
- Percentage.From
- Single.From
2023-2024 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy