skip to main content
Power BI
    • What is Power BI
    • Why Power BI
    • Customer stories
    • Data visuals
    • Security
    • Power BI Desktop
    • Power BI Pro
    • Power BI Premium
    • Power BI Mobile
    • Power BI Embedded
    • Power BI Report Server
  • Pricing
    • Azure + Power BI
    • Microsoft 365 + Power BI
    • Dynamics 365 + Power BI
      • Energy
      • Healthcare
      • Manufacturing
      • Media
      • Retail
    • For analysts
    • For IT
      • Overview
      • Embedded analytics
      • Power BI visuals
      • Automation
      • Documentation
      • Community
    • Getting started
      • Overview
      • Self-guided learning
      • Webinars
      • Documentation
      • Roadmap
      • Overview
      • Issues
      • Give feedback
    • Blog
    • Business intelligence topics
    • Overview
    • Forums
    • Galleries
    • Submit ideas
    • Events
    • User groups
    • Community blog
    • Register
    • ·
    • Sign in
    • ·
    • Help
    Go To
    • Microsoft Power BI Community
    • Welcome to the Community!
    • News & Announcements
    • Get Help with Power BI
    • Desktop
    • Service
    • Report Server
    • Power Query
    • Mobile Apps
    • Developer
    • DAX Commands and Tips
    • Custom Visuals Development Discussion
    • Health and Life Sciences
    • Power BI Spanish Community
    • Translated Spanish Desktop
    • Power Platform Integration - Better Together!
    • Power Platform Integrations
    • Power Platform and Dynamics 365 Integrations
    • Training and Consulting
    • Instructor Led Training
    • Galleries
    • Community Connections & How-To Videos
    • COVID-19 Data Stories Gallery
    • Themes Gallery
    • Data Stories Gallery
    • R Script Showcase
    • Webinars and Video Gallery
    • Quick Measures Gallery
    • 2021 MSBizAppsSummit Gallery
    • 2020 MSBizAppsSummit Gallery
    • 2019 MSBizAppsSummit Gallery
    • Events
    • Ideas
    • Custom Visuals Ideas
    • Issues
    • Issues
    • Events
    • Upcoming Events
    • Community Engagement
    • T-Shirt Design Challenge 2023
    • Community Blog
    • Power BI Community Blog
    • Custom Visuals Community Blog
    • Community Support
    • Community Accounts & Registration
    • Using the Community
    • Community Feedback
    cancel
    Turn on suggestions
    Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
    Showing results for 
    Search instead for 
    Did you mean: 
    • Microsoft Power BI Community
    • Galleries
    • Quick Measures Gallery
    • SVG Sparklines - Categorical Columns

    SVG Sparklines - Categorical Columns

    08-14-2018 09:53 AM - last edited 08-14-2018 10:11 AM

    deldersveld
    MVP
    1905 Views
    LinkedIn LinkedIn Facebook Facebook Twitter Twitter
    deldersveld
    deldersveld
    MVP
    • Mark as New
    • Bookmark
    • Subscribe
    • Mute
    • Subscribe to RSS Feed
    • Permalink
    • Print
    • Report Inappropriate Content

    SVG Sparklines - Categorical Columns

    ‎08-14-2018 09:53 AM

    Power BI now allows the dynamic creation of Scalable Vector Graphics (SVG) images. Prior to the August 2018 version, it was possible to build SVG content into custom columns, but now it is possible to create measures that dynamically update to account for user selections and filters. 

     

    For additional detail on the method, please see this post on the DataVeld blog: Use SVG Images in Power BI: Part 3

     

     

    Get the DAX: SVG Sparkline "Column" measure formula on GitHub

     

     

    Substitute your own measure in place of [Measure Value], a column for 'Table'[Customer Segment] for the categorical X axis, and a column for 'Table'[Category] that will appear on the same table row as the sparkline.

     

    Since the x axis is categorical, it is built and sorted using RANKX. Bar Width is found by dividing 100 by the number of distinct categories, and columns are adjusted to the range 0-100 by multiplying Rank * Bar Width.

     

    The y axis is complex because of the need to account for a mix of positive and negative values. If all Y values were positive, the axis could use [Measure Value] / Max and would be fairly simple. Instead, depending on the combination of positive only, negative only, and mixing negative and positive values, there are SWITCH( ) statements used for establishing both the SVG Y value and the Height of the bar.

     

    CONCATENATEX combines the separate SVG rectangles.

     

    IF(HASONEVALUE('Table'[Category])[...] helps hides the total in a Table or Matrix because the total renders as text and not an image.

     

    Once the sparkline measure is ready, set the Data Category to Image URL and add the sparkline measure to a Table or Matrix visual.

     

    In addition, change the BarColor variable from static to dynamic to create conditional color formatting. In this example, if the Margin % is not greater than 20%, the sparkline should be grey instead of green. Because Firefox will not render # in SVG, substitute %23 in place of # if using hex colors.

     

    //Note: use %23 instead of # for Firefox compatibility
    VAR BarColor = IF([Margin] > 0.20,"%2301B8AA","%23BBBBBB")

     

    Create additional variables for stroke width or any applicable SVG property and subsitute new variables into the SVG text as needed.

     

    eyJrIjoiM2ZjNTQ1OTItMmIyYi00ZWE5LTg3OWMtNjMxM2M5OWUzMzkxIiwidCI6ImFjYzhhYWE1LWYxOTEtNDgyZi05MjFiLWNmNmMzM2E1ODgzMiIsImMiOjF9

    Preview file
    51 KB
    Power BI SVG Sparklines - Column.pbix
    Labels:
    • Labels:
    • Other
    Message 1 of 1
    1,905 Views
    0
    Reply
    • All forum topics
    • Previous Topic
    • Next Topic

    Power Platform

    • Overview
    • Power BI
    • Power Apps
    • Power Pages
    • Power Automate
    • Power Virtual Agents

    • Sign in
    • Sign up

    Browse

    • Solutions
    • Partners
    • Consulting Services

    Downloads

    • Power BI Desktop
    • Power BI Mobile
    • Power BI Report Server
    • See all downloads

    Learn

    • Guided learning
    • Documentation
    • Support
    • Community
    • Give feedback
    • Webinars
    • Developers
    • Blog
    • Newsletter

    © 2023 Microsoft

    Follow Power BI

    • Privacy & cookies
    • Manage cookies
    • Terms of use
    • Trademarks
    Consumer Privacy Act (CCPA) Opt-Out Icon Your Privacy Choices