PowerBI knows how to map devices in a chart

PowerBI is my favorite tool for simple visualizations of telemetry. It’s pretty easy, fast and it integrates so well with StreamAnalytics.

Next to a lot of chart types, it also supports maps. There are actually two kinds op maps:

  1. Map (Location, Legend, Latitude, Longitude, Size, Color Saturation, Tooltips)
  2. Filled Map (Location, Legend, Latitude, Longitude, Color Saturation, Tooltips)

The first chart shows a map with devices represented as circles, big and small ones, depending on a value passed. The second one is more into coloring parts on the map: a state, a country, a city.

The first map supports using latitude/longitude or showing the location using geocoding (passing a Location like ‘Eindhoven’). The second chart only supports geocoding.

In this blog, we will pass a latitude and longitude.

But what kind of latitude and longitude do we have to pass? There are several kinds of formats. Luckily these PowerBi people are not sleeping and it just needs the Decimal Number format.

And how do you get these? Well, if you do not have a GPS, use google maps. I pick a point on the map and ask: What’s here? (“Wat is hier?” in Dutch), using the right click:

pi09

… the location is shown at the bottom of the browser:

pi10

As seen in previous blogs about PowerBI, we could just pass some JSON, coming from StreamAnalytics. But this time, we will use the Get Data abilities of PowerBI to import test data. This takes a lot of effort away generating JSON messages.

Passing JSON is not smart

So I constructed this JSON message by hand:

{
"devicename":"DeviceOne",
"lumen":600.0,
"lat": 51.443556,
"lon":5.447180,
"size": 200,
"tooltipone": 1,
"tooltiptwo":2
}

I passed it to the import functionality. I choose Import or Connect to data; Files. Although the ‘button’ tells nothing about JSON, I still proceed:

pi04

And then I choose local file:

pi05

A file picker is shown. the JSON file is not available directly. Let’s force it, select it anyway using the All Files filter!

After selecting the JSON file, we got this error:

pi07

So the JSON format is definitely not supported (duh). There is some documentation that tells us only Microsoft Excel (.xlsx or .xlsm), Power BI Desktop (.pbix) and Comma Separated Value (.csv) are supported.

So let’s give Excel a try.

Passing plain Excel data is not smart

So I constructed this simple Excel file, just some rows with a header in the first sheet:

pi08

It contains a few more rows compared to the JSON attempt but it’s the same (kind of) data. If I select the new Excel file, I get another error:

pi02

It can also come in a more elaborate (still not very helpful) version:

pi03

But the message is still the same: Within the excel sheet, the data table must be transformed into an actual Excel table (press CTRL-T within the data).

So I did that:

pi11

Now let’s try it again.

Import data using  Excel with an Excel table

The new Excel file seems to be accepted. I choose the “Import Excel data into PowerBI” option:

pi01

And finally, the file is imported (this could take a moment):

pi12

Constructing the chart

Now I have constructed a map by selecting the right values for each property while constructing it:

pi13

For each property I choose no, one or more value:

  • Location: devicename
  • Legend: Empty
  • Latitude: Average of lat
  • Longitude: Average of lon
  • Size: size
  • Color saturation: lumen
  • Tooltips: tooltipone and tooltiptwo

Average latitude and Average longitude

Why do I pass the average location values? Because PowerBI asks me to do that:

pi06

The location property is an alternative for latitude and longitude. I could pass ‘London’, ‘Nebraska’ or ‘Germany’. But I do not have these values for geocoding. Therefore, I am asked to pass the average values of latitude and longitude for the unique devices.

Size and Tooltips

The size is just what you think it’s is. It’s the size of the circle representing the device, from small to large. It’s relative to the value associated with the size property.

The field tooltips is not that descriptive. But the usage is quite simple too. Each location shown has a tooltip, a block box which will appear when you hover over the circle. In that tooltip all subsequent tooltips are shown:

pi14

The legend

People with a good eye for detail will see in the map just shown, the color of some cities is darker than in others. This is the color saturation which depends on the lumen value (because I picked them).

There is an interesting alternative for the color saturation. If that field is left empty and the lumen value is attached to the legend property instead, each city gets another color:

pi15

Conclusion

Showing devices on a map is very easy using PowerBI. All it takes, are the right values in the telemetry passed into the chart. I hope, with these simple tricks, you can build your own powerful dashboards. Look here for more information.

Advertenties