This tutorial will teach you to build a chart with an accompanying Excel-style data table in a Paginated Reports using Power BI Report Builder. This format is great when you have categorical data that you want to display graphically but also provide detailed values that can be easily referenced. For this tutorial, I use sales data split up by product category and display this for each month of a given year. A big thanks to Jason Thomas who first demonstrated how to build this in SSRS.
To get started, all you will need is Power BI Report Builder installed on your machine. If you don’t already have this installed, you can find the free download for Power BI Report Builder here.
Connect to Data
Before you get started building your chart and data table, you need to connect to a data source. For this tutorial, you can use any one of the AdventureWorks sample databases. These databases are freely available for download and are great for educational purposes. I am specifically using the AdventureWorks database from the Power BI Paginated Reports in a Day course. You can follow this tutorial with any version of the AdventureWorks databases. Depending on which version you have your field names may vary slightly from what is shown in this tutorial (i.e. EnglishProductCategoryName vs. CategoryName).
With your own AventureWorks database set up, you can connect to it as a data source in Power BI Report Builder.
- In Power BI Report Builder, right click on Data Sources in the Report Data pane and select Add Data Source.
- In Select connection type pick Microsoft Azure SQL Database or Microsoft SQL Server depending on where you have you AdventureWorks database.
- Click Build and enter your credentials, saving your password.
- Click OK in Connection Properties and then after testing your connection and then OK in Data Source Properties.
Create a Dataset
- Right click on Datasets in the Report Data pane to add a dataset. From the data source dropdown, select the data source you just connected to.
- If you are using the AdventureWorks data source from the Paginated Reports in a Day course, you can simply enter the following query into the Query field and click OK.
SELECT FactInternetSales.ProductKey ,FactInternetSales.OrderDateKey ,FactInternetSales.SalesAmount ,DimDate.DateKey ,DimDate.EnglishMonthName ,DimDate.MonthNumberOfYear ,DimDate.CalendarYear ,DimDate.FullDateAlternateKey ,DimProduct.EnglishProductName ,DimProductSubcategory.ProductSubcategoryKey ,DimProductSubcategory.EnglishProductSubcategoryName ,DimProductCategory.ProductCategoryKey ,DimProductCategory.EnglishProductCategoryName FROM DimProductSubcategory INNER JOIN DimProductCategory ON DimProductSubcategory.ProductCategoryKey = DimProductCategory.ProductCategoryKey INNER JOIN DimProduct ON DimProductSubcategory.ProductSubcategoryKey = DimProduct.ProductSubcategoryKey INNER JOIN FactInternetSales ON DimProduct.ProductKey = FactInternetSales.ProductKey INNER JOIN DimDate ON FactInternetSales.OrderDateKey = DimDate.DateKey WHERE DimDate.CalendarYear = 2019 GROUP BY FactInternetSales.ProductKey ,FactInternetSales.OrderDateKey ,FactInternetSales.SalesAmount ,DimDate.DateKey ,DimDate.EnglishMonthName ,DimDate.MonthNumberOfYear ,DimDate.CalendarYear ,DimDate.FullDateAlternateKey ,DimProduct.EnglishProductName ,DimProductSubcategory.ProductSubcategoryKey ,DimProductSubcategory.EnglishProductSubcategoryName ,DimProductCategory.ProductCategoryKey ,DimProductCategory.EnglishProductCategoryName
- If using a different AdventureWorks data source, select Query Designer.
- From the database tables, you will need to select sales amount, sales dates including both month number and month name, and product category names.
- In the Applied filters section of the Query Designer, add a filter for a specific calendar year. This tutorial uses 2019.
Start Building in Power BI Report Builder
Now that you have connected to a data source and built your query, it’s time to start building the chart and data table.
- Drag and drop an empty matrix onto your canvas.
- Add EnglishProductCategoryName as the row field, EnglishMonthName to the column field, and SalesAmount to the data field.
- Running the report right now, columns are sorted by months alphabetically. Obviously, this isn’t what we want. To sort from January through to December, select your data field and then open Group Properties. Withing the Sorting tab change to sort by MonthNumberOfYear.
- Add two rows above the bottom row with Outside Group – Above.
- Now you can delete the top row (but not the associated group) as shown.
- Now we want to add the month name above the data value. Here, I just want to display the first three letters of the month. Select the cell above [Sum(SalesAmount)] and enter the following expression:
- You can also do some quick formatting, hiding the textbox for the three textboxes as shown below as well as setting the data type for [Sum(SalesAmount)] to Currency.
- Time to start working on the chart. Insert a stacked column chart onto the canvas outside of your matrix.
- With the chart selected, drag SalesAmount to Values, MonthNumberOfYear to Category Groups, and EnglishProductName to Series Groups.
- Delete the chart title, legend, and horizontal axis from the chart.
- Next, to dynamically set the maximum value of the vertical axis, right click the top left textbox of the matrix and select Expression. Enter the following expression (where “EnglishMonthName” is the name of the Column Group in the matrix) and make note of the name of this textbox (mine is named Textbox7 as seen in the properties pane):
- Set the font colour to white to hide this expression.
- Select Vertical Axis Properties and set the maximum value equal to the following expression, replacing Textbox7 with the name of your respective textbox identified in Step 11:
- Select the vertical axis and switch HideLables to True and disable MajorTickMarks.
- Before placing the chart in the matrix, we need to make sure there are no whitespaces in the chart area. Select the chart area and change the properties shown below.
- Ensure the BorderStyle property is set to None.
- Drag and drop the chart into the top right matrix cell and adjust the row height.
- We need to ensure the vertical axis is only displayed for the first column. Select the vertical axis and set the LineStyle property to the expression below, replacing “dsChartsDataTables” with the name of your dataset.
- Add a column inside the group to the left of EnglishProductCategory.
- This column will be our colour column. We can use the Custom Code for consistent colours as described here. Then set the BackgroundColor property for the column and Color property for chart series equal to the following expression, where “EnglishProductCategoryName” is your row group name:
- Now you can Run the report and you will see sales data broken up by product category and month in both chart and data table formats. You’re done! Please leave any comments/feedback/questions in the comments.