Search

Search this blog:

Search This Blog

Fourth Day of Christmas: Report Themes and Design


🎵 On the fourth day of Christmas, my true love gave to me... 

Custom theme colors,

Appended queries,

Table expanded columns

and

a PDF in Power BI🎵

Customize Power BI Report Themes

Today's post is a little fun interlude. If you haven't been following the 12 Days of Christmas blog series, that's okay. We're not actually going to do anything with the data today. We are going to focus on making the report look pretty.

Power BI themes have been around for a long time, but they were previously really inaccessible. You needed to know JSON to be able to edit the theme. I actually taught myself a bit of JSON in order to increase the default font size on all my reports I used in class. Here's my attempt at a JSON larger font size theme that I wrote myself over a year ago: 

  "name": "GlobalLevelTemplate", 

        "dataColors": ["#107C10", "#A80000", "#0078D7", "#915203", "#D79A12", "#bb7711", "#114400", "#aacc66"],

        "background":"#FFFFFF",

        "foreground": "#3A6108",

        "tableAccent": "#568410",

  "visualStyles": { 

         "*": { 

             "*": { 

                 "title": [{ 

                     "show": true, 

                     "fontColor": { "solid": { "color": "#E0521f" } }, 

                    "background": { "no fill": { "color": "#FFFFFF" } }, 

                     "alignment": "center", 

                     "fontSize": 12, 

                     "fontFamily": "Arial" 

                 }], 

"values": [{

"fontSize": 12,

"fontFamily": "Arial"

}],

"rowHeaders": [{

"fontSize": 12,

"fontFamily": "Arial"

}],

"columnHeaders": [{

"fontSize": 12,

"fontFamily": "Arial"

}],

"categoryAxis": [{

"fontSize": 12,

"fontFamily": "Arial"

}],

"*": [{

"fontSize": 12,

"fontFamily": "Arial"

}],

                 "background": [{ 

                     "show": false,

                     "color": { "solid": { "color": "#FFFFFF" } }, 

                     "transparency": 25 

                 }], 

                 "lockAspect": [{ 

                     "show": true 

                 }], 

                 "border": [{ 

                     "show": false, 

                     "color": { "solid": { "color": "#565a5c" } } 

                 }], 

                 "visualTooltip": [{ 

                     "type": "Default" 

                 }], 

                 "stylePreset": [{ 

                     "name": "None" 

                 }] 

             } 

         }, 

         "page": { 

             "*": { 

                 "background": [{ 

                     "color": { "solid": { "color": "#FFFFFF" } }, 

                     "transparency": 50 

                 }], 

                 "outspace": [{ 

                     "color": { "solid": { "color": "#FFFFFF" } }, 

                     "transparency": 50 

                 }] 

             } 

         } 

     } 

 } 

Since April 2020, we don't have to waste time messing with JSON code and toiling over syntax errors because custom theme dialog went general availability. Let's look at what Power BI can do for us using the built in interface.

A picture is worth a thousand words, so I'll let you explore and play with this one on your own:



And here's the JSON output: 

{"name":"High Contrast","dataColors":["#107C10","#A80000","#0078D7","#5C2D91","#004B50","#0E00D7","#D83B01","#B4009E"],"background":"#FFFFFF","foreground":"#070f25","tableAccent":"#0F1934","textClasses":{"label":{"fontSize":16},"title":{"fontSize":20},"header":{"fontSize":20}},"visualStyles":{"page":{"*":{"outspace":[{"color":{"solid":{"color":"#107C10"}}}]}},"*":{"*":{"outspacePane":[{"checkboxAndApplyColor":{"solid":{"color":"#107C10"}}}]}}}}

Really? That's it?! Much more concise and elegant than what I had attempted, and infinitely easier to use. I'll leave you to tinker with the built in Theme Customizer. Pick some nice Christmas colors, your company brand colors, or your favorite colors. Remember to think about accessibility too. Worldwide, 8% of men and 0.5% of women are color blind, with red-green color blind being the most common. Even though red and green are a great Christmas combo, do not rely on them alone to distinguish data series in a pie or stacked column visual. 

Page Formatting

If you haven't discovered the Paint Roller icon in Power BI, find it now. It's in the Visualizations pane of your report and changes depending on what you have selected. If you want to format the report canvas (aka Page) then deselect all visuals and click the paint roller. 


Power BI reports default to a 16:9 page size as they are usually viewed from a computer screen, but you can change this (for example if you are creating a custom tooltip page). 

Page Background vs Wallpaper

Today we're going add some pizazz to our report with background images, but should we do this with Page background or Wallpaper? Examine the animation below and see if you can spot the difference between Power BI Wallpaper and Page background.



Power BI Wallpaper sits behind the report page. Note that when wallpaper transparency is at 0%, as we resize the page, the wallpaper stays fixed. This means that the slicer visual moves closer to Santa's beard. 

Power BI Page background changes the report page itself. Note that when Page background is at 0% transparency, there is a white strip under Santa when we resize the report page, and the slicer stays the same distance from Santa's beard.

I like to think of the Page background like shopping for stationery, whereas Wallpaper is more like shopping for an easel, or as Microsoft put it; wallpaper.

Tune in again tomorrow for the next gift in the 12 Days of Christmas series where we'll delve into DAX and see how the SELECTEDVALUE() function can add meaning and context to your reports in a dynamic way.

Third Day of Christmas: Append Queries


Append Queries in Power BI

🎵 On the third day of Christmas, my true love gave to me... 

Appended queries,

Table expanded columns

and

a PDF in Power BI🎵

If you have been following this 12 Days of Christmas blog series, you will have also noticed that the Naughty or Nice list of data we are using has two names per row. Yesterday we decided to focus only on the first two columns. 

That leaves us today with the challenge of extracting the information from the last two columns, and combining all data into one table with only two columns. There are a few ways we could do this, I am going to show you how to do it without any custom coding required. 



Task 1: Duplicate and Edit Query

Our first task for today is to duplicate the SantaList1 query that we created yesterday. Simply right click on the SantaList1 in the Queries pane and choose Duplicate.


This is absolutely one of my favorite features of Power Query. Here's a few reasons why:

  • There's no 'undo' button in Power Query, so if I want to mess with a query, I'll duplicate it first as a backup. Only when I have everything working will I delete that duplicate backup.
  • Data is full of patterns, and duplicating queries lets me take advantage of those patterns. I can repeat the same steps with minor changes VERY quickly using Duplicate queries.
  • Quite simply, how can you not love a copy paste function?

Okay, now for the minor changes. We need to edit this Query so that it expands Column3 and Column4. Do we remember where that step is?

Pro tip: Rename your Applied Steps and use the Properties to add descriptions to make your Applied Steps easier to understand. Do this for all steps that you think are either ambiguous or important. 

You never know when or what you'll need to edit later, so take the time to make good notes for your future self. Trust me, it's worth your time. As you can see in the image below, descriptions show up when you hover your mouse over the name of the Applied Step:

Click the Settings Cog next to the Expanded Data step, select Column3 and Column4 (deselect Column1 and Column2).

Click on Filtered Rows1 step - looks like we have an error to resolve. Since we're going with the no code method, let's just delete this step and add it back in. Again, notes to yourself can help immensely here so that you don't have to guess what you were trying to achieve at this stage of the query.

We were removing the gibberish (in this case null) table of contents data. 

Hang on, is that truly what we want? To remove anything that's null? Actually, if we're being precise (and we should ALWAYS be precise when working with Power BI) we want to KEEP anything that says "Naughty" or "Nice" and ONLY rows that say "Naughty" or "Nice". 

So let's do a more explicit filter this time. Click the filter arrow on Column4 and select Text Filters > Equals. You should get a Filter Rows box appear: 


Pro tip: Know your data, and be precise with your query. This will ensure it is future proof and refreshes properly even with changes in the data source.

How to duplicate and edit query:

  1. Open the SantaList.pbix file from yesterday. 
  2. Right click on SantaList1 in the Queries pane and Duplicate.
  3. Rename this new query to SantaList2.
  4. Click the Settings cog next to the Expanded Data step to edit.
  5. Untick Column1 and Column2 and tick Column3 and Column4.
  6. Filter Column4 using Text Filters > Equals
    1. equals Naughty
    2. Select Or
    3. equals Nice
    4. Click OK
  7. Save the file. Apply Later.

Task 2: Append Queries

Our second task for today is to append SantaList1 and SantaList2 into one table. 

What does append actually mean? If you look carefully at the image above, you'll notice that two tables are being combined on top of each other. Power BI will match the column names in each table, and combine into one big table. 

I love overcomplicating things, and learning from my mistakes. I'm also a firm believer in seeing things first hand, so just for fun, let's see what happens if we don't rename the column headings. Choose SantaList1 and SantaList2 for your append queries. Scroll up and have a look at the GIF at the top of this blog to see what happens. We end up with a new query that has four columns. Well that's silly, I though we were trying to get rid of the four column structure of our data?

Right, so we need to understand how append works - it looks at the column names of each table, and if there is a column with the same name in the other table, it combines them into one long column. It does this all the way across the table. So what happens with the left over columns that don't have matching names? Good news - they don't disappear. As you can see in the GIF at top, all columns are preserved. This is my number one indicator that my data didn't have an exact match when I did an append:

  1. Check total number of columns
  2. Append Queries
  3. Confirm total number of columns hasn't changed

How to Append Queries (the right way):

  1. Select SantaList1.
  2. Rename Column1 to "Name" and Column2 to "Naughty or Nice?"
  3. Set Data Type to Text.
  4. Select SantaList2.
  5. Rename Column3 to "Name" and Column4 to "Naughty or Nice?"
  6. Set Data Type to Text.
  7. In the Home tab, click Append Queries as New.
  8. Select Santa List 1 and Santa List 2.
  9. Rename this Query to Santa List.
  10. Right click on Santa List 1 in the Queries pane and choose Disable Load. Do the same with Santa List 2. We don't need these in our report since they only tell half the story. We'll use the complete list we created in the append.
  11. Close and Apply the changes.
  12. Save the file.
Hurray! Pat yourself on the back. You've finished everything in Power Query. The data model is now complete for this report. That's plenty for today. Tune in again tomorrow for the next gift in the 12 Days of Christmas series where we'll have some fun exploring Power BI report themes, colors and background photos. 

Second Day of Christmas: Expand Data tables in Power Query


Combine over 400 tables using Expand Data in Power Query

🎵 On the second day of Christmas, my true love gave to me... 

Table expanded columns

and

a PDF in Power BI🎵

There are many ways to combine and append data in Power BI. As we saw in yesterday's post, all our tables have the same format, so we don't need to do any transformations to them before the append. The source step of getting data from PDF lists all the tables, including their underlying data, in one big query. This means we can just expand the columns in the Source query to access all the data.

To do this, we need to go back a few steps to the Source step so we can see all the data in our PDF. 

Skip to the How To: section below to see step by step instructions.

As we noted before, Power BI recognises PDF tables and pages. We don't want to bring all the data in twice, so we'll just focus on the Tables for this example (they are typically tidier).

Pro tip: Filtering data is one of the first things you should do in Power Query with any dataset. It can speed up your refresh times and in some datasets supports a nifty thing called 'Query Folding' that basically enables Power BI to outsource a lot of the work (which ultimately speeds things up). 

This means two of the first steps you should do (even before the Changed Type step that Power BI automatically inserts) are:

  1. Choose Columns
  2. Filter Rows

Okay, so let's put that into practice. Start by deleting all the steps except 'Source'. 

Click Choose Columns from the Home tab in the ribbon. In this example, we only need to know what "Kind" of object and the "Data" within that object, so we'll select just these two columns:

Now we can filter for tables only: 


Wonderful, with the efficiencies out of the way, now we are free to focus on what we came here for; extracting that beautiful data from over 400 tables! Ok, so here's the fun part. So many data sources have embedded tables; databases, SharePoint lists, PDFs, Excel files, merged queries, .... I'm sure there's more that I can't think of at the moment. Basically, if you can learn how to access these embedded tables, and demystify the confusing interface that Power Query uses to display them, you will open endless opportunities for data analysis and exploration. 

This dataset is unique, in that it mashes the tables side by side and imports them as one query. The data we want is only two columns:

  • Name
  • Naughty or Nice

But when we try to expand the Data column to extract the columns from the tables, you'll see we have four columns:

  • Column1
  • Column2
  • Column3
  • Column4
Click Load more if you don't see all of these columns.

Expanding all four columns gives us Name, Naughty or Nice, Name, Naughty or Nice. Hang on, what's all this gibberish at the top?


Go back and look at the PDF if you need to - that's another valuable step when working in Power Query. Always understand your data source, what it means, where it comes from and how it might change. Now I can see that gibberish relates to the table of contents.

I really only want two columns, and I need to remove all the rows with table of contents (or anything that doesn't relate to the Naughty or Nice list).

I know Power BI does not allow me to simply cut and paste that data into the format I want. So what to do?

Today we will create two different queries: 

  • SantaList1 for Column1 and Column2
  • SantaList2 for Column3 and Column4

They will be exactly the same otherwise. Tomorrow we'll see how to combine them into one seamless table.

Okay, so we have two challenges: 

  1. Select only Column1 and Column2.
  2. Filter out the table of contents gibberish that we don't need (note I used that key word 'filter' again).

Pro tip: You can edit Applied Steps that you've already completed using the Settings cog. 

That means we don't have to start over, just click the settings cog for Expanded Data step, and deselect Column3 and Column4.

Finally, we can filter out that gibberish. How is this PDF likely to change? I know Column1 has all the names and there's no pattern to that data - each name is unique. What about Column2? What information do we expect to see in Column2 that is valuable to us for this report? 

"Nice" and "Naughty"

Anything else is useless to us. That's easy, just do a filter on Column2 to display only values equal to "Naughty" or "Nice":


Now we have to do that all over again with Column3 and Column4 right? Wrong! Tomorrow we'll see how to duplicate, edit and append this query to capture all the data in one table. 

How to:

  1. Open the SantaList.pbix file you created on Day 1.
  2. Click Transform Data to open the Power Query Editor.
  3. Delete all steps except the Source step.
  4. Rename the Query to SantaList1.
  5. Click Choose Columns in the Home tab in ribbon.
  6. Select Kind and Data. Click OK.
  7. Filter the Kind column to show only Table.
  8. Right click the Kind column and select Remove.
  9. Click the double arrow at the Data column heading to Expand:
    1. Tick Column1
    2. Tick Column2
    3. Untick Use original column name as prefix
    4. Click OK.
  10. Filter the Column2 column to show only "Naughty" and Nice".
  11. Save the SantaList.pbix report. If asked, choose Apply Later.

That's enough for today. Tune in again tomorrow for the next gift in the 12 Days of Christmas series where we'll see how to quickly edit, duplicate and append queries. 

Custom Visual Review: Charticulator

This is not your ordinary custom visual - this is EVERY custom visual. Charticulator puts the power to design and develop custom visuals to ...