Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
gnotcirdec
Frequent Visitor

Comparing latitude and longitude in a table against different table of latitude and longitudes

Hello.

 

I'm trying to compare data points in different tables to see if they are within each other. If tableA latitude and longitude are inside any of the points inside fence indicated by tableB, "isInside" column will return 1, if not 0. I'm looking to do this all in Power Query

 

Here is an example of tableA:

DeviceLatitudeLongitudeisInside
A10333.77519-118.117820
A10434.01295-118.275391
A10533.71391-118.263180

 

Here is tableB (fence):

TopLatitudeTopLongitudeBottomLatitudeBottomLongitude
34.02513433-118.291683134.01119056-118.2682514
34.03056715-118.255505634.02529439-118.2521689

 

Any help would be appreciated!

 

Thank you.

2 ACCEPTED SOLUTIONS
v-jingzhang
Community Support
Community Support

Hi @gnotcirdec 

 

Here is a DAX method. You can create a new column with below code.

Is Inside = 
VAR _table =
    ADDCOLUMNS (
        TableB,
        "IsInsideFlag",
            IF (
                TableA[Latitude] >= TableB[BottomLatitude]
                    && TableA[Latitude] <= TableB[TopLatitude]
                    && TableA[Longitude] >= TableB[TopLongitude]
                    && TableA[Longitude] <= TableB[BottomLongitude],
                1,
                0
            )
    )
RETURN
    IF ( COUNTROWS ( FILTER ( _table, [IsInsideFlag] = 1 ) ) >= 1, 1, 0 )

vjingzhang_0-1652236522800.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

View solution in original post

Try changing the last line of [Is Inside] to

MINX ( FILTER ( _table, [IsInsideFlag] = 1 ), [Location] )

View solution in original post

4 REPLIES 4
v-jingzhang
Community Support
Community Support

Hi @gnotcirdec 

 

Here is a DAX method. You can create a new column with below code.

Is Inside = 
VAR _table =
    ADDCOLUMNS (
        TableB,
        "IsInsideFlag",
            IF (
                TableA[Latitude] >= TableB[BottomLatitude]
                    && TableA[Latitude] <= TableB[TopLatitude]
                    && TableA[Longitude] >= TableB[TopLongitude]
                    && TableA[Longitude] <= TableB[BottomLongitude],
                1,
                0
            )
    )
RETURN
    IF ( COUNTROWS ( FILTER ( _table, [IsInsideFlag] = 1 ) ) >= 1, 1, 0 )

vjingzhang_0-1652236522800.png

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

Hi @v-jingzhang ,

Is there a way to modify the solution to include Text as the result?

 

For example:

gnotcirdec_0-1652482337551.png

 

 

gnotcirdec_1-1652482350721.png

 

 

Any help would be appreciated!

 

Thanks,

Cedric

 

Try changing the last line of [Is Inside] to

MINX ( FILTER ( _table, [IsInsideFlag] = 1 ), [Location] )

Thank you! This works just as well.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.

Top Solution Authors