Professional Documents
Culture Documents
Ebook Pro Power Bi Theme Creation Json Stylesheets For Automated Dashboard Formatting 1St Edition Adam Aspin Online PDF All Chapter
Ebook Pro Power Bi Theme Creation Json Stylesheets For Automated Dashboard Formatting 1St Edition Adam Aspin Online PDF All Chapter
https://ebookmeta.com/product/pro-power-bi-theme-creation-json-
stylesheets-for-automated-dashboard-formatting-2nd-edition-adam-
aspin/
https://ebookmeta.com/product/pro-power-bi-dashboard-creation-
building-elegant-and-interactive-dashboards-with-visually-
arresting-analytics-1st-edition-adam-aspin/
https://ebookmeta.com/product/pro-dax-and-data-modeling-in-power-
bi-creating-the-perfect-semantic-layer-to-drive-your-dashboard-
analytics-1st-edition-adam-aspin/
https://ebookmeta.com/product/pro-data-mashup-for-power-bi-
powering-up-with-power-query-and-the-m-language-to-find-load-and-
transform-data-1st-edition-adam-aspin/
Pro Power BI Architecture 2nd Edition Reza Rad
https://ebookmeta.com/product/pro-power-bi-architecture-2nd-
edition-reza-rad/
https://ebookmeta.com/product/microsoft-power-bi-for-dummies-
jack-hyman/
https://ebookmeta.com/product/learning-microsoft-power-bi-
jeremey-arnold/
https://ebookmeta.com/product/supercharge-power-bi-power-bi-is-
better-when-you-learn-to-write-dax-third-edition-matt-allington/
https://ebookmeta.com/product/beginning-power-bi-2nd-edition-dan-
clark/
Adam Aspin
This work is subject to copyright. All rights are solely and exclusively
licensed by the Publisher, whether the whole or part of the material is
concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in
any other physical way, and transmission or information storage and
retrieval, electronic adaptation, computer software, or by similar or
dissimilar methodology now known or hereafter developed.
The publisher, the authors and the editors are safe to assume that the
advice and information in this book are believed to be true and accurate
at the date of publication. Neither the publisher nor the authors or the
editors give a warranty, expressed or implied, with respect to the
material contained herein or for any errors or omissions that may have
been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.
Theme Basics
Themes are, technically, JSON files. That is, they use the JSON
(JavaScript Object Notation) format to store the definition of how
dashboard objects are formatted. But don’t worry if you have never
used – or even heard of – JSON before now, as I will be explaining all
you need to know about it during the course of this book. The only
thing to retain for the moment is that themes are like external
stylesheets for Power BI (very like the stylesheets that are used by
Microsoft Word, for instance). The advantage of defining formats with
external files is that you can simply send your colleagues themes as
small text-based files that they can then apply in a few clicks to any of
their own Power BI dashboards. Themes can also be integrated into
Power BI templates to accelerate even further the dashboard creation
process.
Themes are applied to Power BI Desktop files. Once loaded, they
become an integral part of the Power BI Desktop .pbix file. The
formatting is then, of course, carried over into the Power BI service
when you publish the dashboard. Moreover, you can switch between
different theme files in a few clicks to try out different formatting
approaches or apply a completely different look and feel. Equally
fortunately, there is nothing definitive about applying a theme file, as
you can switch to another Power BI presentation style based on a
different theme at any time. So you are free to experiment with
different styles until you find the look and feel that suits the particular
dashboard that you are creating.
A theme allows you to preset virtually anything that is defined in
the Power BI formatting pane. Consequently, it can contain formatting
definitions for
The color palette
The page
Inserted objects (text boxes, shapes, buttons, and images)
Built-in visuals (tables, charts, maps, and other visuals)
You can even apply a theme to the Power BI Desktop Filter pane.
The principle is simple: if you can alter presentation in the formatting
pane of Power BI Desktop, then you can define the format using a
theme file.
The portable nature of dashboard themes means that there are now
a wide range of different themes that are freely available to enhance the
presentation of Power BI dashboards. You may even have experimented
with some of the themes that are available as an integral part of Power
BI Desktop or shared through the Web.
After reading this book and learning how these themes are created,
you, too, will be able to develop themes that you can share – with
friends, colleagues, or even the world.
Anatomy of a Theme
It is important to understand from the start that themes operate at two
distinct levels. Firstly, themes can be defined to operate in a “generic”
way. That is, you can define a set of high-level specifications to set core
aspects of a dashboard and the visuals it contains without going into
low levels of detail. This way you can quickly and easily define
Colors
Standard font attributes
Shared elements for all visuals
Certain elements specific to certain types of visuals
You will discover how to create “generic” themes in Chapter 3.
Then, at a more detailed level (and once you have acquired a
thorough understanding of how themes work), you can specify the
exact formatting for each and every element of each visual to give you
total control of the appearance of each element in a dashboard. An in-
depth definition of the JSON that is required at the level of individual
visuals is the subject of Chapters 5 through 12.
However, don’t get the idea that you have to choose between two
different approaches. The truth is that a theme JSON file can “mix and
match” the two approaches so that you can both define a set of overall
style principles and then add highly specific definitions of the way that
you want certain visuals to be displayed in a dashboard. The principle
will always be that a more generic level of formatting applies unless a
more detailed definition is found in the theme file.
Applying Themes
Before looking at how you create your own themes, it is probably best
that I remind you of the far-reaching effects that themes can deliver.
Hopefully, this will incentivize you to want to learn more and encourage
you how to create your own theme files.
Take, for instance, a very simple dashboard like the one shown in
Figure 1-2. (This is the file SampleDashboard.pbix from the sample
files.)
5. Click Open. After a few seconds, you will see the dialog in Figure 1-
3.
Note The theme file that you applied in this example is not
designed to show off subtleties of dashboard design – nor is it based
on cutting-edge design principles. It is, however, designed to
illustrate how quick and easy it is to reformat an entire dashboard
using a theme file.
Conclusion
In this chapter, you have seen what themes are all about and exactly
how powerful they can be. It is time, now, to move on to creating your
own themes. Initially, we will begin by using Power BI Desktop to write
the JSON for you – as you will discover in the next chapter.
© The Author(s), under exclusive license to APress Media, LLC, part of Springer
Nature 2021
A. Aspin, Pro Power BI Theme Creation
https://doi.org/10.1007/978-1-4842-7068-4_2
If you do not come from an IT background (or have never used JSON
files before), and the thought of hand-crafting complex text structures
fills you with dread, then now is the time to relax and breathe deeply,
because it is ridiculously easy to define a simple yet powerful Power BI
theme file without writing or modifying a single line of code.
This is because Power BI Desktop allows you to specify (in a few
clicks) a core subset of formatting attributes that will apply to your
entire dashboard. Not only that, but once you have defined these
attributes, Power BI Desktop will write the JSON theme file for you so
that you can use it in other dashboards – or share with colleagues. All
this is done using the Customize current theme option of the Themes
button in the View menu.
While this approach does not let you craft every precise formatting
attribute of each individual type of visual, it does allow you to create a
standard presentation style in a few minutes at most – and you can
subsequently take this theme as a basis for further development. What
is more, the resulting theme file is an excellent introduction to how
JSON themes function in Power BI.
Be aware, nonetheless, that creating themes using the Power BI
Desktop interface does not allow you to attain the sophisticated levels
of presentation that you can deliver using “hand-crafted” JSON. So it is
best to consider the techniques that you will discover in this chapter
both as a practical introduction to the subject of themes and also as an
extremely fast way of developing simple style principles that can be
applied to entire dashboards.
To provide a little structure to the process, this “interactive theme
generation” directly inside Power BI Desktop breaks down the theme
elements that you can alter into the following five categories:
Name and colors: Where you can give your theme a name and
specify the color palette and key colors to use in a dashboard
Text: Where you can define core text attributes such as font, size,
and color for various elements in a dashboard
Visuals: Where you can specify key common attributes of all
visuals
Page: Where you can set basic attributes of the dashboard pages
Filter pane: That allows you to specify the way that the filter pane
appears
You do not have to specify every option that Power BI Desktop
makes available in the Customize current theme dialogs. You can
change a couple of options – or reset everything that is available (and
all steps in between).
2. Click the popup for the Themes. You will see something like the
options shown in Figure 2-1.
Figure 2-1 The Themes popup
3. Click Customize current theme. The dialog shown in Figure 2-2 will
appear.
4. Select different colors for the first few Theme colors in the dialog
(these correspond to the colors in the standard Power BI color
palette, from left to right starting at the third column). It is worth
noting that you cannot alter the first two (monochrome) colors in
the color palette.
5. Click Apply. The selected colors will be applied to the current
dashboard.
8. Click Save.
That is it! You now have a fully functioning JSON theme file that you
can apply to other dashboards. You can see the effect of the theme
simply by displaying the Color popup for any element in a dashboard
where this theme file has been applied. You will see that the top row of
the available colors has changed to display the colors that you selected
in step 4 earlier (well, for all but the first two colors which will always
remain white and black).
The choices that you just made are, fortunately, not set in stone. So
you can alter the theme settings at any time by repeating the process
that you just applied and selecting any of the available options and
resaving the theme file.
Note When you resave a theme file, Power BI Desktop does not
remember the name that you last used and will default to
Theme.json. Remember to select the previous file name before
clicking Save if you want to update the existing file. You will, of
course, have to confirm that you wish to overwrite the existing file.
Text Settings
As you might expect, there is also a set of text formats that you can
define as part of a custom theme. Again, to make defining the elements
easier, they are subset into a number (four in this case) of distinct
elements. These subelements are
General: Formats table and matrix column headers, matrix row
headers, table and matrix grid, table and matrix values
Title: Formats category axis title, value axis title, multi-row card title,
slicer header
Cards and KPIs: Formats card data labels, KPI indicators
Tab headers: Formats key influencers headers
Each of the tables corresponding to one of these subelements allows
you to set the
Font
Font size
Font color
Let’s look at each of these subelements individually.
The Customize theme/Text/General tab looks like Figure 2-5.
The Customize theme/Text/Cards and KPIs tab looks like Figure 2-7.
Figure 2-7 The Customize theme/Text/Cards and KPIs tab
To give you some idea of how these text formats are applied, take a look
at Figure 2-9. Please note that this drawing is not a complete reference
– once again, the idea is simply to show you how the principle of
general color settings works.
Figure 2-9 Anatomy of high-level text customization
Note You can see from this image that the colors defined in the
name and colors section override colors set in the text section.
Visual Settings
All visuals in Power BI contain a core set of elements whose format you
can define globally. This ensures a standard look and feel for all the
built-in visuals that you create in a dashboard. The elements that you
can define are
Background: The background color and transparency of a visual
Border: The visual’s border attributes
Header: A visual header (including its visibility)
Tooltip: The colors of the popup tooltip elements
Each of these elements corresponds very closely to the standard
cards (also called elements or sections) that you are used to dealing
with when formatting visuals in the format pane of Power BI Desktop.
They show the same attributes that you have probably tweaked many
times, but presented slightly differently.
Let’s take a detailed look at the way that these settings can be
customized by looking at the four tabs in the Visuals section of the
Customize theme dialog.
The Customize theme/Visuals/Background tab looks like Figure 2-
10. This tab lets you set the color of the background for all visuals as
well as the level of transparency.
Page Settings
There are two settings that you can modify as far as defining the page
formatting when creating a JSON theme file with Power BI Desktop is
concerned. These are
The wallpaper (the area outside the page itself)
The page background (the color of the page underneath any visuals)
These settings are accessed using the Customize theme/Page dialog.
The Customize theme/Page/Wallpaper tab looks like Figure 2-14.
Figure 2-14 The Customize theme/Page/Wallpaper tab
As you can see in Figure 2-15 the Customize theme/Page/Page
background tab, you can also set the color and transparency of the page
background.
Figure 2-15 The Customize theme/Page/Page background tab
The second pane (shown in Figure 2-17) that you can use is the
Customize theme/Filter pane/Available filter cards tab. This contains
options to define (for the filter cards inside the filter pane)
Background color
Transparency
Font and icon color
Font size
“What is a man
If his chief good and market of his time
Be but to sleep and feed? A beast, no more.
Sure, He that made us with such large discourse,
Looking before and after, gave us not
That capability and Godlike reason,
To rust unused.”
1.
The Richmond Enquirer, a strong and influential pro-slavery
newspaper of Virginia, in advocating some railroad projects, thus
describes the progress of the State relatively to that of some of the
Free States, since the Revolution. (Dec. 29, 1852.)
“Virginia, anterior to the Revolution, and up to the adoption
of the Federal Constitution, contained more wealth and a
larger population than any other State of this Confederacy.
***
“Virginia, from being first in point of wealth and political
power, has come down to the fifth in the former, and the
fourth in the latter. New York, Pennsylvania,
Massachusetts, and Ohio stand above her in wealth, and
all, but Massachusetts, in population and political power.
Three of these States are literally chequered over with
railroads and canals; and the fourth (Massachusetts) with
railroads alone. * * *
“But when we find that the population of the single city of
New York and its environs exceeds the whole free
population of Eastern Virginia, and the valley between the
Blue Ridge and Alleghany, we have cause to feel deeply
for our situation. Philadelphia herself contains a population
far greater than the whole free population of Eastern
Virginia. The little State of Massachusetts has an
aggregate wealth exceeding that of Virginia by more than
one hundred and twenty-six millions of dollars—a State,
too, which is incapable of subsisting its inhabitants from
the production of its soil. And New York, which was as
much below Massachusetts, at the adoption of the Federal
Constitution, in wealth and power, as the latter was below
Virginia, now exceeds the wealth of both. While the
aggregate wealth of New York, in 1850, amounted to
$1,080,309,216, that of Virginia was $436,701,082—a
difference in favour of the former of $643,608,134. The
unwrought mineral wealth of Virginia exceeds that of New
York. The climate and soil are better; the back country,
with equal improvements, would contribute as much.”
The same journal adds, on another occasion:—
“In no State of the Confederacy do the facilities for
manufacturing operations exist in greater profusion than in
Virginia. Every condition essential to success in these
employments is found here in prodigal abundance, and in
a peculiarly convenient combination. First, we have a
limitless supply of water power—the cheapest of motors—
in localities easy of access. So abundant is this supply of
water power that no value is attached to it distinct from the
adjacent lands, except in the vicinity of the larger towns.
On the Potomac and its tributaries; on the Rappahannock;
on the James and its tributaries; on the Roanoke and its
tributaries; on the Holston, the Kanawha, and other
streams, numberless sites may now be found where the
supply of water power is sufficient for the purposes of a
Lawrence or a Lowell. Nor is there any want of material for
building at these localities; timber and granite are
abundant; and, to complete the circle of advantages, the
climate is genial and healthful, and the soil eminently
productive. * * * Another advantage which Virginia
possesses, for the manufacture of cotton, is the proximity
of its mills to the raw material. At the present prices of the
staple, the value of this advantage is estimated at 10 per
cent.”
The Lynchburg Virginian, another newspaper of respectability,
having a similar purpose in hand, namely, to induce capitalists to
invest their money in enterprises that shall benefit the State,
observes that—
“The coal fields of Virginia are the most extensive in the
world, and her coal is of the best and purest quality. Her
iron deposits are altogether inexhaustible, and in many
instances so pure that it is malleable in its primitive state;
and many of these deposits in the immediate vicinity of
extensive coal-fields. She has, too, very extensive
deposits of copper, lead, and gypsum. Her rivers are
numerous and bold, generally with fall enough for
extensive water power.
“A remarkable feature in the mining and manufacturing
prospects of Virginia is, the ease and economy with which
all her minerals are mined; instead of being, as in England
and elsewhere, generally imbedded deep within the
bowels of the earth, from which they can be got only with
great labour and at great cost, ours are found everywhere
on the hills and slopes, with their ledges dipping in the
direction of the plains below. Why, then, should not
Virginia at once employ at least half of her labour and
capital in mining and manufacturing? Richmond could as
profitably manufacture all cotton and woollen goods as
Lowell, or any other town in New England. Why should not
Lynchburg, with all her promised facility of getting coal and
pig metal, manufacture all articles of iron and steel just as
cheaply, and yet as profitably, as any portion of the
Northern States? Why should not every town and village
on the line of every railroad in the State, erect their shops,
in which they may manufacture a thousand articles of daily
consumption, just as good and cheap as they may be
made anywhere? * * *
“Dependent upon Europe and the North for almost every
yard of cloth, and every coat, and boot, and hat we wear;
for our axes, scythes, tubs, and buckets—in short, for
everything except our bread and meat!—it must occur to
the South that if our relations with the North should ever
be severed—and how soon they may be, none can know
(may God avert it long!)—we would, in all the South, not
be able to clothe ourselves. We could not fell our forests,
plough our fields, nor mow our meadows. In fact, we
would be reduced to a state more abject than we are
willing to look at even prospectively. And yet, with all these
things staring us in the face, we shut our eyes, and go on
blindfold.”
At the Convention for the formation of the Virginia State Agricultural
Society, in 1852, the draft of an address to the farmers of the State
was read, approved, and once adopted by the Convention. The vote
by which it was adopted was soon afterwards reconsidered, and it
was again approved and adopted. A second time it was
reconsidered; and finally it was rejected, on the ground that there
were admissions in it that would feed the fanaticism of the
Abolitionists. No one argued against it on the ground of the falsity or
inaccuracy of these admissions. Twenty of the most respectable
proprietors in the State, immediately afterwards, believing it to
contain “matter of grave import,” which should not be suppressed for
such a reason, united in requesting a copy of it for publication. In the
note of these gentlemen to the author, they express the belief that
Virginia now “possesses the richest soil, most genial climate, and
cheapest labour on earth.” The author of the address, in his reply,
says: “Fanaticism is a fool for whose vagaries I am not responsible. I
am a pro-slavery man—I believe it, at this time, impossible to abolish
it, and not desirable if it were possible.”
The address was accordingly published, and I make the following
extracts from it:—
“ADDRESS TO THE FARMERS OF VIRGINIA.
“‘The Southern States stand foremost in agricultural
labour, though they hold but the third rank in population.’
At the head of these Southern States, in production, in
extent of territory, in climate, in soil, and in population,
stands the Commonwealth of Virginia. She is a nation of
farmers. Eight-tenths of her industry is expended upon the
soil; but less than one-third of her domain is in pasturage,
or under the plough.
“Out of somewhat more than thirty-nine millions of acres,
she tills but little over ten millions of acres, or about
twenty-six and a quarter per cent., whilst New York has
subdued about forty-one per cent., or twelve and a quarter
out of her twenty-nine and a half millions of acres: and
Massachusetts, with her sterile soil and inhospitable
climate, has reclaimed from the forest, the quarry, and the
marsh, about forty-two and a half per cent., or two and
one-eighth out of her little territory of five millions of acres.
Yet, according to the census of 1840, only six-tenths of the
labour of New York, and four-tenths of that of
Massachusetts, or, relatively, one-fifth and two-fifths less
than our own, is expended upon agriculture. * * *
“The live stock of Virginia are worth only three dollars and
thirty-one cents for every arable acre; but in New York
they are worth six dollars and seven cents, and in
Massachusetts four dollars and fifty-two cents.
“The proportion of hay for the same quantity of land is, for
Virginia, eighty-one pounds; for New York, six hundred
and seventy-nine pounds; for Massachusetts, six hundred
and eighty-four pounds. * * *
“With access to the same markets, and with hundreds of
mechanics of our own, who can vie with the best Northern
manufacturers, we find that our implements are inferior,
that the New York farmer spends upon his nearly three
times as much as we do upon ours, and the
Massachusetts farmer more than double. * * *
“Manure is indispensable to good husbandry. Judging from
the history of agriculture in all other countries, we may
safely say, that farming can never attain to continued
perfection where manure is not put on with an unsparing
hand. By far the larger part of this can only be made by
stock, which should, at the same time, be made the
source of profit, at least sufficient to pay the cost of their
keep, so that, other things being equal, it is a safe rule to
estimate the condition of a farming district by the amount
of live stock it may possess, and the provision made for
their sustenance. Applied in this instance, we see that the
New York farmer has invested in live stock two dollars and
seventy-six cents, and the Massachusetts farmer one
dollar and twenty-one cents per acre more than the
Virginia farmer. In pasturage we cannot tell the difference.
It is well, perhaps, for the honour of the State, that we
cannot. But in hay, New York has five hundred and ninety-
eight pounds, and Massachusetts six hundred and three
pounds more per acre than we have. This, however, does
not present the true state of the case. Land-locked by
mountain barriers, as yet impassable for the ordinary
agricultural staples, or debarred from their production by
distance and prohibitory rates of transportation, most of
the wealth and exports of many considerable portions of
our State consists of live stock alone. What proportion
these parts bear to the whole, we have been unable
definitely to ascertain; but it is, no doubt, so great as to
warrant us in assuming a much more considerable
disparity than the statistics show in the live stock of the
whole Atlantic slope, as compared with New York and
Massachusetts. And we shall appreciate, still more highly,
the skill of the Northern farmer, if we reflect that a readier
market for every, the most trivial, product of his farm,
operates as a constant temptation to break up his rotation
and diminish his stock.
“In the above figures, carefully calculated from the data of
authentic documents,[76] we find no cause for self-
gratulation, but some food for meditation. They are not
without use to those who would improve the future by the
past. They show that we have not done our part in the
bringing of land into cultivation; that, notwithstanding
natural advantages which greatly exceed those of the two
States drawn into parallel with Virginia, we are yet behind
them both—that with forty and sixty per cent. respectively
of their industry devoted to other pursuits, into which it has
been lured by prospects of greater gain, they have done
more than we have done. * * *
“Whilst our population has increased for the last ten years,
in a ratio of 11·66, that of New York has increased in a
ratio of 27·52, and that of Massachusetts at the still
heavier and more startling rate of 34·81. With a territorial
area thirty per cent. larger than New York, we have but
little more than one-third of her Congressional
representation; and Massachusetts, only one-eighth our
size, comes within two of our number of representatives,
we being cut down to thirteen, while she rises to eleven.
And thus we, who once swayed the councils of the Union,
find our power gone, and our influence on the wane, at a
time when both are of vital importance to our prosperity, if
not to our safety. As other States accumulate the means of
material greatness, and glide past us on the road to
wealth and empire, we slight the warnings of dull statistics,
and drive lazily along the field of ancient customs, or stop
the plough, to speed the politician—should we not, in too
many cases, say with more propriety, the demagogue?
“State pride is a good thing; it is one mode in which
patriotism is manifested. But it is not always a wise one.
Certainly not, when it makes us content on small grounds.
And when it smothers up improvement in self-satisfaction,
it is a most pernicious thing. We have much to be proud of
in Virginia. In intellect and fitness to command, in personal
and social qualities, in high tone and noble bearing, in
loyalty, in generosity, and magnanimity, and
disinterestedness, above all, in moral purity, we once
stood—let us hope, still stand—preeminent among our
sister States. But the possession and practice of these
virtues do not comprise our whole duty as men or as
citizens. The great decree which has gone forth ordaining
that we shall ‘increase, and multiply, and replenish the
earth,’ enjoins upon us quite other duties, which cannot be
neglected with impunity; so we have found out by
experience—for we have neglected these duties. And
when we contemplate our field of labour, and the work we
have done in it, we cannot but observe the sad contrast
between capacity and achievement. With a wide-spread
domain, with a kindly soil, with a climate whose sun
radiates fertility, and whose very dews distil abundance,
we find our inheritance so wasted that the eye aches to
behold the prospect.”
2.
The Census of 1850 gives the following values to agricultural land in
the adjoining States of Virginia and Pennsylvania.
In Virginia. In Pennsylvania.
No. of acres 10,360,135 8,626,619
improved land in
farms,
" 15,792,176 6,294,728
unimproved,
Cash value of farms, $216,401,543— $407,876,099—
$8 an acre. $25 an acre.
Considering that, at the Revolution, Virginia had nearly twice the
population of Pennsylvania, was in possession of much more wealth
or disposable capital, and had much the best natural facilities for
external commerce and internal communication, if her political and
social constitution had been and had continued equally good, and
her people equally industrious and enterprising with those of
Pennsylvania, there is no reason why the value of her farms should
not have been, at this time, at least equal to those of Pennsylvania.
Were it so, it appears that Virginia, in that particular alone, would
now be richer than she is by four hundred and thirty millions of
dollars.
If it should be thought that this difference between the value of land
in Virginia and Pennsylvania is in some degree due to more fertile