Fun with Flags – Country Emojis as Data Labels in Power BI

Sometimes, a seemingly straightforward request brings a fascinating technical challenge. Recently, an old friend expressed the wish to display country flags as symbols on the bars in a stacked bar chart. Initially, this idea seemed a bit humorous, but I was intrigued by the technical challenge. In this post, I’ll show how I fulfilled this wish using country emojis and a special font—and the hurdles involved in the process.

The Challenge: Flags as Data Labels

Power BI does not offer an option to directly integrate flags or other custom symbols as data labels. Therefore, I had to devise a creative approach to represent country flags through emojis. I created a measure that automatically translates the countries from the legend into appropriate emojis to display as data labels. A pragmatic solution, though not without some limitations.

Flag Emoji = 
    SWITCH (
        SELECTEDVALUE ( 'Fact'[Geography] ),
        “USA”, ‘🇺🇸’,
        “Europe”, ‘🇪🇺’,
        “Germany”, ‘🇩🇪’,
        “Emirates”, ‘🇦🇪’,
        “Italy”, ‘🇮🇹’,
        “Mexico”, ‘🇲🇽’,
        “Austria”, ‘🇦🇹’,
        “United Kingdom”, ‘🇬🇧’,
        “Brazil”, ”🇧🇷”
    )
Power BI Desktop with Measure Flag Emoji as Data Label

The Pitfalls: Country Emojis in the Browser

One complication was the display of country emojis in different browsers. In Microsoft Edge and Chrome, country flags are not displayed as colorful symbols but only as country codes (e.g., “DE” for Germany). However, Firefox displays the flags as emojis. These differences are due to how each browser processes and displays emoji fonts. To ensure a consistent cross-platform display, a special emoji font was needed.

Power BI Flag Emojis in the Firefox browser

The Solution: Installing and Applying the Font

To correctly display the flags, I installed the emoji font NotoColorEmoji_WindowsCompatible.ttf, available from Google Fonts on GitHub. Here’s the link to the font: NotoColorEmoji.

To make the flag emojis appear in Power BI, this font is specified in the Theme JSON file, allowing the font to be applied to the data labels of the stacked bar chart. Since only standard fonts are available in Power BI Desktop, this workaround with the theme file is essential for displaying flags as data labels.

{
    "name": "Flags",
    "visualStyles": {
      "columnChart": {
        "*": {
          "labels": [
            {
              "fontFamily": "Noto Color Emoji"
            }
          ]
        }
      }
    }
  }
Power BI Flag Emojis with Font Noto Color Emoji

Step-by-Step Guide

  1. Finding Emoji Codes: You can conveniently copy the appropriate emoji codes for the flags from Emojipedia. Each country has its own code, which can then be used as an emoji in Power BI.
  2. Creating the Measure: Create a measure that outputs the country name or code from the legend as an emoji code.
  3. Installing the Font: Install the NotoColorEmoji_WindowsCompatible.ttf so that the emojis appear as flags in Power BI.
  4. Modifying the Theme JSON: In the theme file, ensure that the data labels use the NotoColorEmoji font. This ensures that the font is correctly applied to the data labels of the bar chart in Power BI Desktop.

Conclusion

From a design and information design perspective, using emojis in stacked bar charts can be questionable. This approach may compromise readability and clarity. It’s always worth considering whether this type of visualization truly enhances the information flow or if alternative forms might be more suitable. Additionally, using fonts that are not natively available in Power BI poses challenges, as the specific font must be installed on every device for the report to display correctly.

However, this blog post aims to demonstrate what is technically possible and to inspire creative solutions for technical challenges. The approach showcased here exemplifies the versatility of Power BI for those willing to take unconventional paths.

Veröffentlicht von

Marcus Wegener

Marcus Wegener

Marcus Wegener ist Anwendungsentwickler für Business Intelligence und erstellt Lösungen, mit denen sich große Datenmengen schnell analysieren lassen. Kunden nutzen seine Lösungen, um die Vergangenheit zu analysieren, die Gegenwart zu steuern und die Zukunft zu planen, um damit mehr Erfolg zu generieren. Dabei ist seine einzigartige Kombination aus Wissen und Auffassungsgabe ein Garant für ihren Erfolg.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert

I accept that my given data and my IP address is sent to a server in the USA only for the purpose of spam prevention through the Akismet program.More information on Akismet and GDPR.