Elevating Power BI Reports With HTML & CSS - Joining Forces ? - by Isabelle Bittar - Microsoft Power BI - Feb, 2024 - Medium
Elevating Power BI Reports With HTML & CSS - Joining Forces ? - by Isabelle Bittar - Microsoft Power BI - Feb, 2024 - Medium
Elevating Power BI Reports With HTML & CSS - Joining Forces ? - by Isabelle Bittar - Microsoft Power BI - Feb, 2024 - Medium
com/microsoft-power-bi/elevating-power-bi-reports-with-html-
no other snapshots from this url
search 5 Feb 2024 15:02:17 UTC
webpage capture
All snapshots from host medium.com
Member-only story
24 1
Introduction
HTML (HyperText Markup Language) is the standard programming
language used to create and design web pages. Combined with CSS
(Cascading Style Sheets), which allows for extensive styling and layout
adjustments, these two languages enable the design of virtually any type of
web interface.
While I’m not an expert in HTML/CSS, I’ve been increasingly using them into
parts of my Power BI reports to enhance visual appeal through customized
shapes, icons, and more. This has also helped me simplify or reduce the
number of shapes and measures used in reports for a cleaner look. Many of
you may have already noticed in my PBIX files shared across previous
articles, I often leverage the HTML Content visual that allows us to merge
the capabilities of Power BI with the versatility of HTML/CSS 💪.
Click on the “Get more visuals” three dots (…) from the Visualizations
panel in Power BI.
Select the HTML Content visual. Use the search bar on the right-hand
side to find it faster.
Click on “Add” to import the HTML Content Visual into your Power BI
report.
Importing the HTML Content Visual to Your Power BI Report
What I really appreciate about the HTML Content Visual is the ability to
combine the power of DAX and HTML in the measures you create to make
the most of this visualization. It will become clearer in the following sections
when I go through some examples.
You can check out the documentation for this visualization tool here.
I’ve found that having a basic understanding of HTML has been quite
beneficial in my overall programming journey. I learn best through projects,
which is why I’ll show you some straightforward examples in the next
sections to get you started with using HTML. However, if you prefer learning
through courses, I recommend Codecadmy’s Learn HTML course. I
completed it, along with the CSS course, a few years ago. Each is about 6
hours long and provided me with a solid foundation (I think 😅).
1. Styling Text
I discovered the HTML visual while searching for a method to italicize part
of the text rendered by a measure. Here are some common ways to style text
in HTML:
These HTML tags can be directly incorporated into your measures or fields,
allowing dynamic alterations to text appearance within your reports. This
feature is particularly useful for emphasizing key indicators, highlighting
specific parts or making your report more fancy 😎.
In my report, I styled these text boxes using the HTML Content Visual:
Here’s the DAX measure I created for displaying the “Last semester/Last
Year” text beneath the Average Score KPI:
In this measure, I make the text bold by placing the text I want to highlight
between <b> and </b> tags. To move to a new line, I use the <br> tag. It's
important to note that all HTML tags are included within quotation marks.
When you need to use two or more HTML tags in a row in a DAX measure
(like </b><br> ), you can put them together inside the same set of quotation
marks.
2. Creating Shapes
HTML and CSS provide a powerful toolkit for creating custom shapes
directly within your Power BI reports.
I opted to create these shapes using HTML instead of Power BI’s built-in oval
shape because I wanted to include HTML icons (which we’ll explore in the
next section). Additionally, I needed these ovals to be quite small, and with
Power BI shapes, I wouldn’t have been able to add text and make it fully
visible.
To achieve this, I began by creating a DAX measure titled ‘Oval Set Up’:
This measure uses HTML and CSS to define the look and layout of the oval
shape, with placeholders (between the {} brackets) for customizable
elements. Here’s what each part of the code accomplishes:
1. HTML Structure: The <head> section includes a <meta> tag that ensures
the content is properly scaled on different devices, with width=device-
section within the <head> defines the CSS styles for the oval shape.
color: {FONT_COLOR}; sets the color of the text within the oval, where
{FONT_COLOR} is a placeholder for the text color.
font-size: 10px; specifies the size of the text inside the oval.
The <body> contains a <div> element with the class "oval," applying the
previously defined CSS styles to this div.
Inside the div, a <span> element contains {TEXT} , a placeholder for the
text you want to display inside the oval. The (non-breaking space)
ensures that the text is properly spaced within the oval.
The next measure demonstrates displaying the first oval shape (showing last
semester’s variation) by replacing the {Placeholder} with values defined in
DAX and substituting them into the HTML/CSS code as follows:
Measure for the HTML Content Visual in the Next Code Snippet
is used.
3. Font Color Selection: Similar to the background color, the font color is
also chosen based on the score’s variation. A darker shade of red ( [Color
Red] ) indicates a decrease, while green ( [Color Green] ) signifies an
increase.
5. Shape Customization with HTML: Using the HTML setup from [Oval Set
Up] , it replaces placeholders for background color, font color, and text
with the determined values ( _BackgroundColor , _FontColor , _Text ). This
ensures the visualization appears only when data is available (since only
a few semester are available in the data model).
I personally like the ‘Font Awesome’ icons library because of its modern
look. So far, I have been only using the free ones, but there is also a
membership option if you want to access some of the fancier/trendier ones.
In my report, I’ve added up and down arrow icons leveraging the Font
Awesome icons library.
Since I sometimes use many icons from this library, like the Oval shape, I
first set up a DAX measure with placeholders that are then replaced.
1. Responsive Design Setup: The <meta> tag in the <head> section ensures
that the content is optimized for display across different devices by
setting the viewport to match the device's width and scale the content
appropriately. This means the icon will look good whether viewed on a
desktop, tablet, or smartphone.
2. Accessing Font Awesome Icons: The <link> tag imports the Font
Awesome stylesheet from a CDN (Content Delivery Network). This
stylesheet provides the styles for all Font Awesome icons, making them
accessible for use in the report by referencing their specific class names.
3. Icon Display and Customization: The <i> tag is used to insert an icon
into the HTML content. The class attribute specifies which icon to
display using {ICON_CODE} (a placeholder for the icon's specific class
name from Font Awesome) and {SIZE} (a placeholder for the icon size,
using Font Awesome's size modifiers like fa-lg for large). The style
attribute is used to set the icon's color through {COLOR} , a placeholder to
be replaced with the desired color code.
Then, to create the arrow icons, I replace the placeholder values in measures
like the following for the Green Arrow Up:
specifies the use of a solid, upward-trending arrow icon from the Font
Awesome library. This icon is chosen to visually represent positive
growth or improvement, typically used in KPIs or metrics that have
increased.
fa-lg , fa-xl , and fa-2x to fa-10x ) to allow for easy resizing of icons.
Choosing fa-md ensures that the icon is neither too small nor too large,
making it visually balanced within the context it's used.
You can view the DAX measures of all the other icons created in this Power
BI report leveraging the Font Awesome icon library by downloading the PBIX
file available at the end of this article. They are all available under the
_Constants/HTML Set Up measure folder.
Custom Styling and Branding: Tailor the look and feel of reports to
match corporate branding or specific design guidelines, creating a
consistent visual experience across all reports.
Wrapping Up
That’s all for this article! We’ve just scratched the surface of what you can do
with HTML and CSS in Power BI, and I hope it got you excited and thinking
of all the opportunities and potential use cases. If you are not too familiar
using HTML, but still want to give this visualization a try, consider leveraging
ChatGPT 🤖 to help you prepare the HTML code you need!
Happy designing 🎨 and stay tuned for my next update in navigating this
challenge 🥸!
X (Formerly Twitter)
👉 Power BI Newsletter
👉 Power BI Masterclass
24 1
235 2 558 7
76 4 88 9
See all from Isabelle Bittar See all from Microsoft Power BI
80 3 1K 12
Lists
90 325
btd Anish Singh Walia in 𝐀𝐈 𝐦𝐨𝐧𝐤𝐬.𝐢𝐨
64 526 11
Help Status About Careers Blog Privacy Terms Text to speech Teams