Make a choropleth map with the Mapbox Visual for Power BI
In this tutorial, you will use the Mapbox Visual in Microsoft Power BI, data with information about US wildfires by state, and a custom tileset with information about US wildfires by county to create a choropleth visualization. This choropleth will display the number of acres burned at both the state and county levels, allowing you to drill into the data at the appropriate level. You will need a Mapbox account and a Microsoft Power BI account to complete this tutorial.
This guide walks through using the Mapbox Visual in Power BI Online. The process in Power BI Desktop is similar, but the interface is different.
Here are a few resources you'll need before you get started:
- Mapbox account. You need a Mapbox account and a Mapbox access token, which you can find on the Account page.
- Microsoft Power BI account. Sign into your Power BI account or create a new one.
- Mapbox Visual for Power BI. You can either add the Mapbox Visual using the Power BI Marketplace, or you can download the latest Mapbox Visual from the open-source GitHub repository. Both of these options are explained in detail in the tutorial.
- Geospatial data. You will upload this GeoJSON file, which contains county-level detail about wildfires in the United States, to Mapbox Studio as a tileset.
- Dataset for Power BI. You will upload this sample dataset, a CSV file that contains historical information about wildfires in the United States, to Power BI.
Before you can reference the geospatial data from the downloaded GeoJSON file in a Power BI report, you need to upload it to Mapbox as a tileset.
To upload geospatial data to Mapbox as a tileset, the data must be in one of the following formats:
- Shapefile (zipped)
For information on upload file size limits for these formats, refer to the Uploads troubleshooting page.
- Navigate to the Tilesets page in Mapbox Studio.
- Click on the New tileset button.
- In the New tileset window, you can either click the Select a file button and choose the file, or you can drag and drop the file directly into the window.
- When you are prompted to do so, click Confirm.
- After the file uploads, you will see a confirmation success message. Click on the link in the confirmation message to open your new tileset’s information page. The tileset's information page includes the tileset ID, the layer's name, and the layer’s properties, all which you will need to reference in Power BI.
You will use these pieces of information in the Add a custom tileset section of this tutorial. For now, though, you will open Power BI.
You will start by adding the wildfire data you downloaded to a new Power BI workspace.
- In Power BI, click Get Data, which allows you to import data or connect to a data source.
- Under the Files option, click Get.
- Choose Local File and upload the wildfire data CSV file.
Your dataset should be a CSV file with at least 2 columns. One column must be a unique identifier, which will be used to match a unique property from your tileset. The second column must be the value you want to connect to the unique identifier. (For the dataset in this example, the unique property is the
state_name, which you will match to the pre-defined Power BI state tileset. The value you connect to the unique identifier will be the number of acres burned.)
- Click on My Workspace and select the Datasets tab.
- Click the Create a report option (the bar graph icon) next to the new dataset. This will open the report window.
You can use the Mapbox Visual for Microsoft Power BI with any dataset that contains geographic data values. To add the Mapbox Visual to your report:
- In the Visualizations pane, click the Import a custom visual option, represented by a three-dot icon.
- Select Import from marketplace.
- Enter "Mapbox" in the search menu and press enter.
- Click the Add button next to the Mapbox Visual option to add it to your Power BI report. After the Mapbox Visual is imported, it will appear as a blue Mapbox logo on the Visualizations pane.
- Click the Import a custom visual icon (three dots) and select Import from file.
- Upload the latest Mapbox Visual.
- A new blue Mapbox logo will appear in the Visualizations pane.
- Click on the Mapbox icon in the Visualizations pane to add a new visualization to your report.
- In the Fields tab, drag the
state_namefield from your data onto the Location shelf. You should see the Mapbox visualization container populate with instructions on how to create your first visualization.
- Connect your Mapbox account using your access token:
- Click the Click here to get a free Mapbox access token link in the visualization container. Accept the external link request if prompted. You will be forwarded to either the Mapbox sign up page or your Mapbox account page.
- Copy your Mapbox Access token from your account page.
- Back in Power BI, go to the Format tab and open the Viz Settings option. Paste your access token in the Access token field.
- In the Viz Settings pane, change the Map Style option to Dark.
- Drag the
ACRESfield from the data options onto the Color shelf.
- Go back to the Format tab. Switch the Circle option off and turn the Choropleth option on.
You will see a choropleth that visualizes the number of acres burned per state.
To drill down more deeply into data about wildfires in the United States, you will reference the custom tileset with information about wildfires at the county level that you created in the first step of this tutorial.
To add this data to Power BI, you will plug its identifying features into the appropriate fields in Power BI. The information that you'll need from the tileset are the tileset ID, the layer name, and the unique identifier property name.
- In the Format tab, click on Choropleth to open the choropleth layer settings.
- Use the Number of levels dropdown menu to change the number of levels to 2. (Having two levels will allow you to drill down from the state-level data in Level 1 into the county-level data that you are adding now.)
- In the Level dropdown, select Level 2.
- Click on the Data Level 2 dropdown.
- Select the Custom Tileset option.
- In the Vector Tile URL Level 2 field, paste the tileset ID. The tileset ID in this field must always be preceded by
- In the Source Layer Name Level 2 field, paste the layer's name.
- In the Vector Property Level 2 field, enter the unique identifier property name:
- Click on the Fields tab again. Drag the
county_idfield from the data options onto the Location shelf.
The boundaries in a custom tileset should contain one unique identifying property key that matches the dataset you are using in Power BI. Common examples are: FIPS code, zip code, ISO code, or any unique name string.
Use the buttons on the upper left side of the visualization to drill up to the state level or down to the county level. Hover over a state or county to see the number of acres burned in that specific boundary.
You have created a choropleth visualization in Microsoft Power BI using the Mapbox Visual for Power BI.
Explore ways to further customize the choropleth. For instance, you could use the Choropleth settings in the Format tab to change the color range of the visualization.
Want to do more with Mapbox and Power BI? Contact Mapbox sales to learn what else is possible, from adding custom shapes to visualize territories, adding detailed indoor maps, or visualizing billions of data points.