Value.Equals is a Power Query M function that checks if value1 is equal to value2. The function returns true if the two input values are equal, false otherwise.
Compatible with: Power BI Service Power BI Desktop Excel Microsoft 365
Syntax
Value.Equals(
value1 as any,
value2 as any,
optional precision as nullable number,
) as logical
| Argument | Attribute | Description |
|---|---|---|
| value1 | ||
| value2 | ||
| precision | optional | The Precision.Type specifies the accuracy level for calculations. When omitting this argument, Power Query uses Precision.Double by default, which, while efficient, may cause rounding errors with very small fractions. For greater accuracy Precision.Decimal offers a more precise number representation, ideal for tasks requiring high precision. |
Description
The Value.Equals function checks whether two values are equal in Power Query M. By default, the comparison is performed using Precision.Double, which can approximate fractional numbers, but you can specify Precision.Decimal for exact equality checks.
Examples
Let’s break down how Value.Equals works, including how precision settings affect its behavior.
Basic Usage
The Value.Equals function returns true if the two values are equal and false if they are not. Here’s a simple example:
Value.Equals( 5, 5 ) // Returns true
Value.Equals( 5, 10 ) // Returns false
It determines whether the two values are identical based on their numerical value.
Precision and Equality
By default, Value.Equals uses Precision.Double, which compares values based on their binary representation. This can lead to results where two seemingly different values are treated as equal due to rounding errors in fractional numbers.
For example:
Value.Equals( 0.3, 0.300000000000000001 ) // Returns true
Value.Equals( 0.3, 0.300000000000000001, Precision.Double ) // Returns true
Here, the function considers 0.3 and 0.300000000000000001 to be equal when using Precision.Double, because the difference is smaller than the threshold of binary precision.
Using Precision.Decimal for Exact Equality
When accuracy is critical, you can use Precision.Decimal to ensure exact comparisons. This precision mode evaluates the values using a fixed decimal system, avoiding the rounding effects of binary representation.
Here’s the same example using Precision.Decimal:
Value.Equals( 0.3, 0.300000000000000001, Precision.Decimal ) // Returns false
With Precision.Decimal, the function correctly identifies that 0.3 and 0.300000000000000001 are not equal, returning false.
Related articles
Learn more about Value.Equals in the following articles:
- Power Query Precision: Avoid Rounding Errors
Learn how to handle precision differences in Power Query. With these tips you can return accurate numbers and prevent rounding errors. » Read more
Related functions
Other functions related to Value.Equals are:
2023-2026 © BI Gorilla. All rights are reserved. Information from Microsoft docs is property of Microsoft Corp. | Privacy Policy