Forum Discussion

oktober42's avatar
oktober42
Frequent Visitor
1 year ago
Solved

DirectQuery latitude and longitude for map

I'm working on a project where we have an MQTT GPS locator on our site. We want to display that locator's current location. We are sending the sensor's data to a Streaming Dataset. I can see and crea...
  • Amar_Kumar's avatar
    1 year ago

    Use a Calculated Column (instead of a Measure):

    Measures are usually aggregated in visuals, which is why you're seeing the error. But if you create a calculated column that captures the latest latitude and longitude, you can ensure that it's not aggregated.

     

    Here's how you can create a calculated column that grabs the most recent location:

    Latest Latitude = 

    CALCULATE(

       FIRSTNONBLANK(YourTable[Latitude], YourTable[Timestamp]),

       FILTER(YourTable, YourTable[Timestamp] = MAX(YourTable[Timestamp]))

    )

     

    Latest Longitude = 

    CALCULATE(

       FIRSTNONBLANK(YourTable[Longitude], YourTable[Timestamp]),

       FILTER(YourTable, YourTable[Timestamp] = MAX(YourTable[Timestamp]))

    )

     

    After creating the calculated columns, add them to the Latitude and Longitude fields in the Map visual.

    For the aggregation, ensure both are set to Don't summarize in the Fields pane. You should now have a single pair of latitude/longitude displayed.

  • v-dineshya's avatar
    1 year ago

    Hi oktober42 ,

    Thank you for reaching out to the Microsoft Community Forum.

     

    You need to create a table that filters to the most recent row without relying on measures inside the visual.

    please try below options:

    Option 1: Use a Calculated Table: If your dataset isn't pure streaming, but rather a hybrid with some static tables, you could create a calculated table that only holds the latest row:

    LatestLocation =
    TOPN(
    1,
    'YourStreamingTable',
    'YourStreamingTable'[Timestamp],
    DESC
    )

    Then you can bind Latitude and Longitude as columns. On the map, they will not need aggregation, and "Don't summarize" will be available. BUT if it's a pure Streaming Dataset, you can't create calculated tables directly. So you may not be able to use this.

    Option 2: Create a Flag Column and Filter:
    Create a calculated column that flags the latest row:

    IsLatest =
    IF(
    'YourStreamingTable'[Timestamp] =
    CALCULATE(
    MAX('YourStreamingTable'[Timestamp]),
    ALL('YourStreamingTable')
    ),
    1,
    0
    )

    Then in the visual, filter IsLatest = 1. Use the columns directly: Latitude, Longitude — they will be columns, not measures. Set both to "Don't summarize". Now you’ll only show the latest location.

    Note: Depending on data volume and DirectQuery latency, the IsLatest column might sometimes lag slightly behind the data.

    Option 3: Use a Card for Display Instead: If you really can’t get around it and maps won't cooperate, as a fallback:
    Display current Lat/Lon in cards. Update the map visual to show all recent points, but highlight the latest one differently.

    Note: Maps are special in Power BI. They expect "Latitude" and "Longitude" fields to be static per row. When you use a measure, Power BI can't understand how to plot it row-by-row. That's why "Don't summarize" is grayed out.

     

    If my response has resolved your query, please mark it as the Accepted Solution to assist others. Additionally, a 'Kudos' would be appreciated if you found my response helpful.

    Thank you