This year I had the wonderful privilege to attend the Microsoft Data Insights summit for 2017 as a speaker. My topic was the Top Ten Tutorials from PowerBI.Tips. So, let me say thank you to all those who attended you provided a very fun audience and were very positive, Thanks. For those of you who couldn’t make it to the Data Insights Summit below is the actual talk:
We went through 10 different tutorials in 50 minutes. Needless to say we went pretty quick. So, if you were there, or just want to go through the tutorials on your own here is the list of the Top Ten Tutorials.
This month we have a big release for Power BI Desktop and for the Power BI service. There are a number of great new features. For the everyday user you will love the new Data bars for the new table & matrix visualizations. For me this really feels like a feature that is making tables and the matrix views feel more like the pivot table and formatting that can be done in excel. Great Job Microsoft!
For the developer who want to who may be using Rest APIs you should definitely check out the newly added feature called Custom Data Connectors. There was an announcement last month which now opens up the world for developers to write custom connectors right in Visual Studio.
The full June release is described in the video below:
Every so often you find a hidden gem, something so valuable, just hiding there in plain sight. Recently, I found out that I LOVE the using Variables with in a DAX expression. Ok, brief introduction, I was trying to calculate sales changes between different years. The data looked similar to the following table:
Year
Month
Sales
2013
1
20
2013
2
25
2014
1
22
2014
2
23
2015
1
21
2015
2
31
I wanted to sum the sales for each year and compare the percent change between each year. If you have followed my blog for a while, I have a ton of tutorials about percent change. ( See list of other tutorials dealing with percent change )
Now, for the twist making this calculation more difficult. I want to calculate percent change even when a filter is applied by clicking on a visual. By using variables we can apply some data modeling voodoo magic to get the desired results. See a sample of the measures working in the Power BI Embedded sample below:
Let’s dive in!
Open up PowerBI Desktop, Click the Get Data button on the Home ribbon and select Blank Query. Click Connect to open the Query Editor. On the View ribbon clickthe AdvancedEditor button. While in the Advanced Editor paste the following code into the editor window, click Done to complete the data load.
Note: If you need some more help loading the data follow this tutorial about loading data using the Advanced Query Editor. This tutorial teaches you how to copy and paste M code into the Advanced Editor.
let
Source = Excel.Workbook(Web.Contents("https://powerbitips03.blob.core.windows.net/blobpowerbitips03/wp-content/uploads/2017/05/Clothing-Sales.xlsx"), null, true),
ClothingSales_Table = Source{[Item="ClothingSales",Kind="Table"]}[Data],
#"Changed Type" = Table.TransformColumnTypes(ClothingSales_Table,{{"Date", type date}, {"Category", type text}, {"Sales", Int64.Type}}),
#"Inserted Year" = Table.AddColumn(#"Changed Type", "Year", each Date.Year([Date]), type number)
in
#"Inserted Year"
Your loaded data should look like the following:
Rename the Query to ClothingSales, and click Close & Apply to load the data into the data model.
It is a good practice to review the data columns and verify that the formatting is set up correctly. To do this click on the the column Date in the Fields pane, then click on the Modeling ribbon. In the Formatting section change the format to Date Time and select M/d/yyyy format. Repeat this for the following columns:
Format Sales to Currency then select $ English (United States)
Format Year to Whole Number
With our data properly formatted we are ready to build a simple bar chart. See the image below for the bar chart set up:
To start we will create a explicit calculation for the total selected sales. On the Home ribbon click the New Measure button and enter the following code:
Total Selected Sales = SUM(ClothingSales[Sales])
Pro Tip: To learn more about explicit vs implicit calculations within Power BI Click the following link.
Add a Card visual and add our new measure.
Let’s change the formatting measure so we can see the full number. With the Card still selected click the Paint Roller expand the section labeled Data label and change the units from Auto to None. This allows us to see the entire sales number.
Let’s enhance this card visual further by adding dollars formatting. Make sure you have the Total Selected Sales measure selected by Clicking on the words of the measure. Then, click on the Modeling ribbon click and change the Format to Currency, then select $ English (United States). The final format of the card visual should look like the image below:
For the next step we will repeat the previous steps for our new measures.
Create the measure
Change the formatting of the card
Change the formatting of the measure
The next measure will calculate the prior year total sales, but only calculate this value when a filter context from a different visual is applied. Take note this is the magic I was talking about!!
Prior Year Sales =
VAR
selectedYear = if( HASONEVALUE(ClothingSales[Year]),
FIRSTNONBLANK(ClothingSales[Year],ClothingSales[Year]),
BLANK() )-1
Return
CALCULATE(
SUM(ClothingSales[Sales]),
ALL(ClothingSales),
ClothingSales[Year] = selectedYear)
I am going to pause a second here and explain what is going on in this measure as we have multiple things going on. First, we are creating a variable with the VAR. In the below image I show you that the variable that we are defining is called selectedYear. SelectedYear returns a value of blank if multiple years are selected. This is accomplished by using the if statement and the HASONEVALUE() DAX formula. The Return in then allows us to output a value. In this case we are using the CALCULATE() to sum all the sales. The next part is crucial to making this work. Within the Calculate we are applying two filters. The first filter selects the entire table with the All() then we apply the filter from the earlier defined variable with the name of selectedYear.
Apply the same formatting steps 2, and 3 mentioned earlier. Now, we can select one of the years within our bar chart. Doing so populates the two measures we created. The selected year total sales, and the prior year of sales. I selected the year of 2014, which has sales of $11k. Hover your mouse over the bar for year 2013 and the tool tip will appear showing a total sales of $10K.
Now we will make our percent change measure. Enter the following as a new measure:
Percent Change = DIVIDE([Total Selected Sales],[Prior Year Sales],1)-1
Pro Tip: Use the DAX function DIVIDE when dividing two numbers, this protects against odd cases where the denominator is zero.
Click on the Modeling ribbon and change the formatting of the measure to Percentage. Add a final measure that calculates the difference. See measure below:
Prior Year Delta = [Total Selected Sales] - if( [Prior Year Sales] = BLANK(), [Total Selected Sales],[Prior Year Sales])
This measure calculates the total changes in sales between the two selected years. The if statement at the end of the equation handles a special case that if you don’t have any individual year selected the prior year delta defaults to zero.
Thanks for following along an learning about variables. Trust me, these are super helpful. Make sure you spend some learning how to leverage variables in your DAX equations.
This Tutorial was inspired by the following article I found from SQLBI authored by the master of DAX Alberto Ferrari. I mean, come on, Ferrari, how baller is that last name! I guess that is why he is the master. Kudos to you Alberto!
Still need more reading about DAX, check out the following books:
It’s that exciting time of month again. Time for another power BI desktop release. This month here are a couple of good highlights you should check out.
First up enhanced tables with word wrapping in both headers and table rows. Woot Woot, I have really needed this feature!
Clicking a row in the table will now allow filtering in other visuals. Similar functionality to the matrix features that we already saw last month.
Enhanced URL links for tables. This on is interesting. If you are an ad agency you should really pay attention to this one. This allows you to embed a mailto command directly in a table. Then you can click the link to send an email to someone directly from Power BI, perfect for following with a sales leads.
Combo charts label density. This feature is one I can really stand behind. Frankly, I didn’t know I needed it, but now that I have seen the light, this will be awesome.
For the full Power BI Desktop release here is the full announcement.
If you want to watch the full video for the release you can see the full video below:
Learn how to use SUM() and SUMX() with this great video from Curbal. As you become more familiar with PowerBI you will increase your understanding of DAX (Database Analysis Expressions). Microsoft has an extensive list of all the expressions you can use found here. One of the more common expressions you will use is SUM and SUMX.
To learn more about DAX I have read both of these book and found them extremely helpful. They both cover the basics and then quickly get you understand how to make complex calculations which you will need to make the right visual work.
Curbal has been generating a lot of great content. To learn about for more information you can visit the website found here, or visit the YouTube Channel.
For more great videos about Power BI click the image below:
This video talks about how to create custom links that apply report level filters. This is super cool and provides a ton of wide flexibility when building drill down reports. In this example Patrick talks to filtering a report based on a Sales Person (Lilly Code). Great technique for drilling down into subsets of data within a report. If implemented in correctly this will enhance the user experience.
Dynamic filtering with PowerBI:
In the above video Patrick has referred to a previous video done by Adam talking about report filters within the URL query string. For convience I have linked the referred video below, so you can watch it all in one place.
If you haven’t already make sure you go check out Adam’s site and YouTube Blog for more great information.
For more great videos about Power BI click the image below:
With another month comes another exciting release of PowerBI desktop. This month we have a number of really interesting features releases. One of the more interesting feature releases you should definitely check out is the Add Column by Example. I have seen a demo of this feature and can definitely see the potential for speeding up the data cleansing process in the query editor. I’ve also included the YouTube video below for this feature.
To read about the full release from Microsoft hit the link here.
The April 2017 Update:
Check out the Add Column by Example demo:
For other great Power BI videos click the image below:
Here is a super helpful video from Guy in a Cube about how to have multiple logins using Google Chrome. Often I find my self juggling between a work account and my PowerBI.Tips accounts to test out various Power BI features. This little trick definitely saves you time and headache when jumping between accounts.
Side note: I also found this great technique works on Azure (portal.azure.com) if you frequent this site for work and for your other adventures.
This week I had a number of team members tell me how difficult it was to share a PBIX file and the corresponding data between team members. The department hasn’t committed 100% to the idea of using PowerBI.com, and thus wanted to share the actual report. I pointed my team mates to my earlier tutorial about using variables for file locations. After reading the tutorial the team came back with a bunch of griping about how they didn’t want to go into the query editor, people name variables different things, and thus it’s hard to understand what another team member was doing, blah, blah, blah…
So, in order to make peace I took another look at trying to make the sharing of a PBIX file easier. This time I decided to use the Parameters feature within PowerBI. This feature within the Query Editor was released all the way back in April of 2016. I read about it, thought it was interesting but couldn’t find a really good use case. In my current predicament, the parameters feature is the perfect solution.
By using a parameter to store a folder and or file location you enhance the user experience by making it easier for a user to change the Query.
To modify a parameter after it has already been built click on the bottom half of the Edit Queries button, found on the Home ribbon. A menu will pop up and you can select Edit Parameters.
The Enter Parameters screen will pop up. This is where you would change the parameters for a query. In our example this is where we will enter a new folder location for our data.
Let’s begin the tutorial. To start we will need to work with some data. In my earlier tutorial, I used the Olympic Medals Count. We will reuse this dataset. Start by downloading the zipped folder Olympic Metal Count files from the following location. Once you have downloaded the sample data, extract the folder and subsequent files from the zipped file. In windows 10, which I am using, you can right click on the downloaded file and select Extract All..
A pop-up window will appear to complete the extraction process. By leaving the default settings the folder will be extracted into the same location as the downloaded file. Click Extract to complete the extraction.
We now have a folder with all our data.
With the data prepared we can now make the parameters within PowerBI. Open PowerBI and click the top half of the Edit Queries button. The Query Editor will open. Click the Mange Parameters found on the Home ribbon. The Parameters screen will open. Click the blue New button at the top left. Enter the name Folder, and include a brief description of this parameter. Since the folder parameter is essential to the query we must leave the Required box checked. Change the Type to Text, and leave the Suggested Values to Any value. Finally enter the Folder Location where our Medal-Count file is located into the Current Value. Click OK to complete the parameter.
Next, we will create the actual query to load the folder containing our Metal Counts. Click on the New Source button. This will open the Get Data window. Select the Folder option located in the list on the right. Click Connect to complete the Get Data.
The Get Data window will close, then a new window asking for the folder location will open. This is where the parameter implementation is slick. Click the ABC button to the far right of the Folder Path bar. Change the selection to Parameter and select our newly created parameter labeled Folder. Click OK to load the Folder.
Next the folder prompt opens allowing us to accept or edit the query. Click Combine & Edit to proceed. The Combine Files window will open. Here we can interrogate each file to inspect what is in each file. Clicking the drop-down menu next to Example File: allows us to see the list of all files. Select the 2004 Medals.xlsx file.
Click the Sheet1 item on the left side of the window. This exposes the data that is contained within this 2004 particular file. Click OK to proceed.
Note: For users that have been working with PowerBI for a while, this Combine Files screen flow is a newer feature. I feel that this greatly simplifies the process and makes it easier to detect issues when loading data.
PowerBI now loads the files into the Query Editor. The Query that we want to use is labeled Query2, change the Query2 name to Metal Count.
What you’ll also notice is there is a lot more queries on the left side of the screen under Queries. These queries were auto generated when we navigated through the menu screens. Click Close & Apply to complete the data load.
Build the following Stacked Column Chart:
Click the Ellipsis on the upper right hand corner of the chart and select Sort By Total to sort all the items in the bar chart according to how many metals each country won.
Great we have made a parameter, loaded multiple excel files, and then made a visual of our data. Let’s test it out. Save your work and close the PowerBI desktop. (don’t forget to save your PBIX)
Next we rename the folder where all the excel files are contained. Change the name to Olympic Medals.
Reopen your PBIX file, on the Home ribbon click the Refresh button. Ooops, since we renamed the folder we now have an error.
To fix this click the bottom half of the Edit Queries button on the home ribbon, and select Edit Parameters. Then modify the Folder field to include the new name of the other folder Olympic Medals. Click OK to proceed.
A message bar will appear under the Home ribbon. Click Apply Changes to complete the data load. PowerBI will reload all your data using the context of the new folder.
Now this is an elegant solution for sharing PBIX files and their corresponding data files with coworkers. This is just a simple example of how you would use parameters. There are a multitude of other really good use cases for using parameters within your queries. Thanks for reading along, be sure to share if you like this tutorial.
March is an exciting month, and with this release of Power BI we have been given some long asked for features. One such feature is the ability to import a color theme. The color theme defines the starting colors for your visuals. Before the ability to import a theme one would have to first define each color that they want to use in a Power BI report by changing each visual to have the correct color scheme. Color themes are useful when trying to make a dashboard and you want to use colors that resemble a company’s product or logo. Alright, let’s get started and make and add our own color theme to a report.
Begin by opening up Power BI Desktop. Make sure you have the latest version of Power BI Desktop, you can download the latest version here. The import color theme feature is available in the March 2017 release.
On the Home ribbon click the Enter Data button. Enter the following table of data and name the table Data.
Product
Value
Item1
20
Item2
25
Item3
15
Item4
40
The Create Table should look similar to the following. Click the Load button to proceed.
Power BI will load the data to memory and the Fields pane will reveal our newly created columns. Add the Stacked Column Chart on the report page and appropriate fields shown in the image below. You will notice that the default colors are automatically overlaid onto our visual when we add the Product to the Legend visual field.
Next, let’s take a peek at the standard colors that are offered by default from Power BI. Click on the Paint Roller found in the Visualizations pane. Then expand the data field labeled Data colors. Under Item1 click the little triangle. This will expose the current color scheme that is loaded.
Now we will load the new color theme. But before we can load the color theme we have to generate the color theme first. The color theme has some requirements. First the color theme must be written as a JSON file and must adhere to the JSON format. For developers this will be a very simple google search to accomplish this. However, I know there are some out there that do not enjoy doing development work. So, in a PowerBI.Tips first, I have developed a custom tool to make the color theme generation super simple.
Introducing the PowerBI.Tips Color Theme Generator (CTG) to help Power BI users create quick and easy JSON code files to input into Power BI for the color themes. Not everyone has a coding background, and though there will be tutorials and examples of how to set up the JSON, if you aren’t familiar with the language a small typo could have you spending precious time troubleshooting the issue.
update 3/15/17: The Advanced Theme Generator has been released. Find the tool here.
Click the following link to open up the PowerBI.Tips Color Theme Generator in a different Browser window. Once the browser loads the Color Theme Generator follow the instructions listed at the top of the page to select your colors. The only required fields are the Name, and at least one color. For this tutorial I selected a number of nice pastel colors. Click the Download Color Theme button to download the JSON file that we will use in Power BI.
Note: The Generator was tested on Google Chrome. Also, clicking the Download button will download the JSON file to your browser’s default location. You will need to know this file location to load the file into Power BI Desktop.
Head back over to Power BI Desktop. On the Home ribbon click the button labeled Switch Theme. Then click Import Theme.
Note: If you want to remove your custom theme you will click on the Switch Theme, then click on the Default Theme. The normal power BI colors will be restored.
Navigate to where your browser downloaded the file. Select the file labeled PowerBI-Tips Color Theme. Click Open to load the theme.
PowerBI will prompt a message letting you know everything loaded correctly. Click Close to see the new theme applied to our visual.
We can now see our custom theme by clicking on the Paint Roller found in the Visualizations pane. Then expand the data field labeled Data colors. Under Item1 click the little triangle.
Tada, now we have a custom color scheme that we create and loaded. Also, now that we the JSON file you can modify the file and keep it for future projects.
Thanks for following along. If you liked this tutorial please be sure to share. Also if you want to know more about me you can visit my About page and follow me on twitter or Linkedin for updates.