# GeometryPoint.From

## # ## What is GeometryPoint.From?

GeometryPoint.From is a Power Query M function that is used to create a point in a two-dimensional coordinate system. The function takes two arguments, x and y, which represent the x and y coordinates of the point. The x and y arguments must be numeric values. The function returns a record that represents the point in the coordinate system.

## Understanding the M code behind GeometryPoint.From

To understand the M code behind GeometryPoint.From, we need to understand the structure of the record that is returned by the function. The record has two fields, x and y, which represent the x and y coordinates of the point. The M code behind GeometryPoint.From is as follows:

(x as number, y as number) =>

[

x = x,

y = y,

type = type nullable number meta [

IsCoordinate = true,

IsNullable = true

]

]

``` The first line of the M code defines the two arguments, x and y, that are passed to the function. The second line creates a record that has three fields, x, y, and type. The x and y fields are assigned the values of the x and y arguments, respectively. The type field is a metadata field that is used to identify the record as a coordinate point. The type field is nullable, which means that it can be null. Using GeometryPoint.From Now that we understand the M code behind GeometryPoint.From, let's look at some examples of how it can be used to work with spatial data in Power Query. Example 1: Creating a point from x and y coordinates Suppose we have a table that contains x and y coordinates for a set of points. We can use GeometryPoint.From to create a new column that contains the points as records. The M code for this transformation is as follows: ```

let

Source = Table.FromRows({{1, 2}, {3, 4}, {5, 6}}, {“x”, “y”}),

in

``` In this example, we start with a table that contains two columns, x and y. We use Table.FromRows to create a table from a list of lists. We then use Table.AddColumn to add a new column, Point, to the table. The new column is created using the GeometryPoint.From function, which takes the x and y values from the current row as arguments. Example 2: Calculating the distance between two points Suppose we have a table that contains two sets of x and y coordinates, representing two points. We can use GeometryPoint.From to create records for each point, and then use the distance formula to calculate the distance between the two points. The M code for this transformation is as follows: ```

let

Source = Table.FromRows({{1, 2, 3, 4}}, {“x1”, “y1”, “x2”, “y2”}),

p1 = GeometryPoint.From([x1], [y1]),

p2 = GeometryPoint.From([x2], [y2]),

dx = p2[x] – p1[x],

dy = p2[y] – p1[y]

in

Math.Sqrt(dx dx + dy dy)),

in

``` In this example, we start with a table that contains four columns, x1, y1, x2, and y2. We use Table.FromRows to create a table from a list of lists. We then use Table.AddColumn to add a new column, Distance, to the table. The new column is created using a let expression that first creates records for each point using GeometryPoint.From, and then calculates the distance between the two points using the distance formula. GeometryPoint.From is a powerful function in Power Query M that can be used to work with spatial data. We have explored the M code behind the function and provided some examples of how it can be used to transform and analyze spatial data. With this knowledge, you can now use GeometryPoint.From to unlock the power of spatial data in Power Query. Power Query and M Training Courses by G Com Solutions (0800 998 9248) Power Query and M Intensive Training Course £1,050.00 – £26,550.00 Select optionsContinue Loading Done Power Query and M Introduction £395.00 – £9,750.00 Select optionsContinue Loading Done Power Query and M Intermediate £395.00 – £9,750.00 Select optionsContinue Loading Done Power Query and M Advanced £395.00 – £9,750.00 Select optionsContinue Loading Done Upcoming Courses Contact Us Subject Your Name (required) Company/Organisation Email (required) Telephone Training Course(s) Power BI Intensive TrainingPower BI introduction Power BI IntermediatePower BI AdvancedDAXPower Query MPower BI CertificationPower BI AdministrationPower PlatformPower AutomatePower AppsOTHER Your Message Upload Example Document(s) (Zip multiple files) ```
``` ```
``` ```
``` ```
``` ```
``` ```