Creating a Custom Shape Map in Power BI of Vietnam's Population by Province: A Step-By-Step Guide
Create a Custom Shape Map in Power BI of Vietnam Population by Province

Creating a Custom Shape Map in Power BI of Vietnam's Population by Province: A Step-By-Step Guide

Location is Everything! Unlock Geospatial Insights with Power BI

?? 80% of business data has a location context. Visualizing the data on a map can unlock spatial insights in a way that a table of numbers simply cannot.

In this article, I’ll show you step-by-step how to enable Power BI’s hidden Shape Map feature and create your first custom map that displays Vietnam’s population at the provincial level. For businesses operating in Vietnam, you can easily swap out the population data for your own sales, expenses, inventory, production, distribution points, etc., using the included Power BI template and shape map visual.?

All source files, as well as the completed Power BI file, can be found in my Github repo for this project at: https://github.com/courtlin-holt-nguyen/pbishapemap

Enable the Shape Map Visual In Power BI

1) Go to File > Options & Settings > Options > Previous Features and click “Shape map visual”. For me, Shape map visual is the first entry in the list

PBI Preview Features Panel. Enable "Shape map visual". Disable "New format pane".

Note: You should also DISABLE the “New Format pane” preview feature when working with Shape Maps in Power BI. The New Format pane option is still in development. Many features in the standard formatting panel are unavailable in the New Format Pane, including setting colors on your Shape Map. You can always re-enable the New Format Pane after customizing your Shape Map if you need to use the new layout pane for some reason.

2) Restart Power BI.

The Shape Mape visual will now appear next to the standard map visuals in Power BI.

The Shape map visual looks slightly different from the standard Filled Map

Obtain and Prep the GeoJSON files

1) You need to find a GeoJSON file for your map with the desired level of detail. For example, if you want to visualize your customers by zip code in the US, you need to find a GeoJSON file of US zip codes. Like this one: https://github.com/OpenDataDE/State-zip-code-GeoJSON

2) GeoJSON files are freely available on Github as well as the open data websites for many governments and NGOs. For this tutorial, I used the GeoJSON file with Vietnam’s provincial boundaries from OpenDevelopmentMekong.org. You can find it here: Provincial administration of Vietnam - Dataset OD Mekong Datahub (opendevelopmentmekong.net)

Choose either "_english"

NOTE: There are English or Vietnamese versions of the GeoJSON file provided. The English version doesn’t include the accent marks on the province names, e.g. “Ho Chi Minh” instead of “H? Chí Minh”. The Vietnamese version of the file includes the correct accent marks. For this tutorial, I used the Vietnamese version of the GeoJSON map file. Use whichever version corresponds to the provincial naming convention used in your dataset.

3) Now that you’ve downloaded the GeoJSON file, you need to convert it into a format that Power BI can use, which is TopoJSON. To do that, you need to convert from GeoJSON to TopoJSON. It’s easy to do; just go to the free website mapshaper.org ( https://mapshaper.org/ )

Drag & drop the GeoJSON file we downloaded in the previous step onto the webpage.

Click Import after dragging and dropping your GeoJSON file

Click Import. You’ll see a map of Vietnam.

mapshaper.org

Click Export in the upper right corner of the website and then choose “TopoJSON” as the format, then click the Export button in the dialog box.

mapshaper.org


A preview of the GeoJSON file from

NOTE: You’ll notice on the website’s map preview image many small islands off the Southern coast of Vietnam. Power BI will shrink the entire Shape Map visual to accommodate these distant islands if you don’t exclude them. To remove them, I manually edited the GeoJSON file to exclude most small islands and focus on the Vietnamese mainland. I also corrected the misspelling of several provincial names in the GeoJSON file to match the Vietnamese government's General Statistics Office names for each province. Always quality-check your source files! ?

4) You can download my edited TopoJSON file with the Vietnamese offshore islands excluded in the resources section for reuse in your other projects.

The file is called: diaphantinhTOPO-edited.json

For the remainder of this tutorial, I’ll use this edited TopoJSON file

You’ve just finished the most difficult technical part of this tutorial! Now we just need to add our data and configure the Shape Map in Power BI to make an interactive visual map of Vietnam’s provinces.

Import Your Data To Power BI

This section is standard Power BI work, so I’ll go through it quickly and then proceed to configure the Shape Map visual. If you have any questions, let me know in the comments.

1) Get Data > Excel Workbook

For this tutorial, I’ll use the included Excel file of Vietnam’s 2022 population broken down by province. This data was obtained from the General Statistics Office of Vietnam (Note: I used the Vietnamese language version of the page, the English version of the page has an error) https://www.gso.gov.vn/px-web-2/?pxid=V0203-07&theme=D%C3%A2n%20s%E1%BB%91%20v%C3%A0%20lao%20%C4%91%E1%BB%99ng

The file name is VN population by province 2022 Only.xlsx

2) Rename the query “Population”

3) Transform the data by promoting the headers, rename Column 1 to “Province”

4) Click Close & Apply

You should see the table Population in the Fields column

The simple data we've used for this tutorial will appear in the Fields list

Build the Shape Map visual

This is the last section. Configuring the basic shape map is very easy now that we have done the above prep work. Fortunately, for any future shape map that you create requiring Vietnamese provinces, you can reuse the prep steps above.

1) Drag the Shape Map tile to the PBI canvas. You’ll see a blank map image appear.

A blank shape map visual

2) Under the Fields property, drag “Province” into the Location area

Configure the data for the shape map visual

3) Under the Fields property, drag “2022” into the Color Saturation area ?

4) You’ll see the blank map image change to a map of the USA as Power BI tries to figure out what “Province” means. Let’s fix this.

5) Click the Format property of the visual, expand the Shape setting, click “+ Add map”, select the saved TopoJSON file. In this tutorial, I’m using the file, diaphantinhTOPO-edited.json

Set the shape map to use a custom TopoJSON map file

6) If you’ve followed the steps above, you’ll see the map switch to a view of Vietnam with the provincial borders colored blue to indicate the number of people living in each province. ?

7) Done! The finished shape map is below.

Shape map in Power BI Desktop

You can also publish the shape map to the Power BI service on Microsoft Fabric.

Shape Map published on Microsoft Fabric

The finished Power BI Desktop file is included in the Github repo as a Power BI Template file named PBI Shape Map Vietnam Provinces Population V2.pbit. To use it, open the PBI Template file and enter the directory path location for the population data Excel file on your computer, e.g. C:\Users\Courtlin\Downloads\VN population by province 2022 Only.xlsx

then click the Load button.

NOTE: Make sure you don't include quotation marks (" ") around the file path, or Power BI will have an error about illegal characters.

Enter the file path location where you saved the input Excel data file on your PC. Click Load

Conclusion

?This concludes the basic tutorial on Shape Maps in Power BI. In the next tutorial, we’ll extend the example and make it more useful for the typical business analyst by adding a longer historical dataset, adding a YoY% change in population measure and adjusting the Shape Map to show diverging colors. We’ll also add slicers and animation.

?? Let me know what you thought of this tutorial and if you have any questions in the comments below.

?? Don't forget to repost this article if you found it useful and think other people in your network would benefit from having the source files.

Thanks for reading and reposting!

#PowerBITutorial #ShapeMaps #DataVisualization #BusinessAnalytics #LearningPowerBI #BIInsights

Huynh Nguyen Van

Technical Sales Manager (PU) at Golden Highway (VietNam) Co, ltd

11 个月

Thankyou! It's very detail

回复
Huynh Nguyen Van

Technical Sales Manager (PU) at Golden Highway (VietNam) Co, ltd

11 个月

Thankyou! It's very detail

回复
C? V?n T?n

Lead Data Analyst for Digital Broker Department

1 年

Thank you so much

回复
Gia Phú

Supply Chain Planning

1 年

Thank you. It is easy to follow

回复
Courtlin Holt-Nguyen

Head of Data @ QIMA - AI, BI, Data Engineering and Smart Productivity | Author | ex- Head of Enterprise Analytics for a Fortune 500 FMCG company in Vietnam | Data Strategy, Analytics, ML, Data Scientist

1 年

?? Here's the link to download the project files from Onedrive: https://hi.switchy.io/I2lr

回复

要查看或添加评论,请登录

Courtlin Holt-Nguyen的更多文章

社区洞察

其他会员也浏览了