Number.Atan2
NumberReturns the angle in radians between the positive x-axis and the point (x, y), correctly handling all four quadrants.
Syntax
Number.Atan2(y as nullable number, x as nullable number) as nullable numberParameters
| Name | Type | Required | Description |
|---|---|---|---|
y | number | Yes | The y-coordinate (vertical component). |
x | number | Yes | The x-coordinate (horizontal component). |
Return Value
number — The angle in radians in the range (-π, π].
Remarks
Number.Atan2(y, x) computes the angle θ (in radians) between the positive x-axis and the point (x, y). The result is in the range (-π, π]. This is the two-argument form of the arctangent that correctly handles all four quadrants by considering the signs of both x and y independently.
Critical: the parameter order is y first, then x. This is the standard mathematical convention and matches how ATAN2 works in Excel. A common mistake is reversing the arguments — Number.Atan2(x, y) will give the wrong angle for any non-symmetric point.
The advantage over Number.Atan(y/x) is quadrant correctness: for the point (-3, -4), y/x = 4/3 and Number.Atan(4/3) gives ~53°, but the correct angle is ~−127° (third quadrant). Number.Atan2(-4, -3) correctly returns ~−127°. Additionally, Number.Atan2 handles the case x = 0 without division-by-zero — it returns ±π/2 depending on the sign of y.
To convert the radian result to degrees, multiply by 180 / Number.PI. All Power Query M trigonometric functions work in radians, not degrees.
Examples
Example 1: Angle to the point (1, 1) — 45 degrees
Number.Atan2(1, 1) * 180 / Number.PIResult | |
|---|---|
| 1 | 45 |
Example 2: Angle to a negative-x point (180 degrees)
Number.Atan2(0, -1) * 180 / Number.PIResult | |
|---|---|
| 1 | 180 |
Example 3: Compute bearing angle in degrees to a 2D coordinate
let
X = 3,
Y = 4,
AngleDegrees = Number.Atan2(Y, X) * 180 / Number.PI
in
AngleDegreesThe final output — the bearing angle in degrees from the positive x-axis to the point (3, 4).
Result | |
|---|---|
| 1 | 53.13 |