How it works...

To convert from Cartesian coordinates (x and y) to polar coordinates, we need to compute the distance from the pole, in this case, coordinates 0, 0, to the reference point provided by the x and y coordinates with which we are working. This distance is called the radial coordinate, radial distance, or simply radius, and is often simply denoted as r. Thus, our first calculation is to calculate r and this is simply an implementation of using the Pythagorean theorem to calculate the hypotenuse of a right triangle with two known sides.

The second part of the polar coordinate system is called the angular coordinate, polar angle, or azimuth. The polar angle is often denoted by the Greek symbol for theta. This angle is expressed in either degrees or radians. 2π radians = 360 degrees. To compute this angle, we generally take the arctangent, or inverse tangent, of our x, y style coordinate. However, we need to account for the quadrant in which our reference point lies. In addition, we must also account for the way in which the DAX function for arctangent, ATAN, operates. The DAX function, ATAN, returns values in radians in the range of -π/2 and π/2. Thus, the SWITCH statement for our theta column simply has a list of conditions for calculating the value of theta. The first condition simply checks whether x is greater than 0 and, if so, the calculation for theta is straightforward. The second condition is for calculating theta when the reference point lies in the upper-left quadrant. The third condition takes care of the reference point being in the lower-left quadrant. The next two conditions account for the angle being 90 degrees or -90 degrees.