I have done quite a bit of reporting over the years, from text-based reports with ToolBook applications, Crystal Reports from within VB 6 applications, SQL Server Reporting Services, and, one of my favorites prior to Power BI, Microsoft Report Viewer. In this chapter, I wanted to explore how a Report Viewer implementation might be adapted for Power BI. So I chose one of our own products, our Tracker.Net Learning Management System (LMS).1 It expands on our previous “direct to SQL Server” example. We have a simpler database structure and show how we can test our query in SQL Server Management Studio and then implement it directly within Power BI. We also look at the important topic of how to edit your drill-down interactions so they filter the other visuals rather than highlight their matching values.
Report in Tracker.Net
Let’s first take a quick look at the original interface. As shown in Figure 14-1, Tracker.Net allows a user with “Reporter
” access to select between Student, Lesson, Course, Class, Organization, and Division reports. Here we select all the lessons and then choose the Student Information* report.2
The user then selects the Display button to see the result in Figure 14-2. Microsoft’s Report Viewer control
gives the interface with the layout controlled by its *.rdlc file.3
Since I am using what Report Viewer calls ProcessingMode.Local, our .NET code connects to the database directly, runs our query (taking account of the selected lesson(s) and the report requested),4 and then sets the report’s DataSource property. Figure 14-3 shows how this looks in SQL Server Management Studio when grabbing all lesson data.
Notice how the query joins the Organizations, Students, StudentLessonInformation, and Lessons tables. Notice also how there are 333 total records. We will check this when we get to Power BI. Listing 14-1 shows the Standard Query Language (SQL) query
:
FROM Tracker_Lessons INNER JOIN Tracker_Students INNER JOIN Tracker_StudentLessonInformation ON Tracker_Students.StudentID = Tracker_StudentLessonInformation.StudentID INNER JOIN Tracker_Organizations ON Tracker_Students.OrganizationID = Tracker_Organizations.OrganizationID ON Tracker_Lessons.LessonID = Tracker_StudentLessonInformation.LessonID
WHERE (Tracker_Lessons.Inactive IS NULL OR Tracker_Lessons.Inactive = 0) AND (Tracker_Students.EmploymentStatus IS NULL OR Tracker_Students.EmploymentStatus = 0)
ORDER BY Tracker_Lessons.LessonLongName, Tracker_Students.LastName, Tracker_Students.FirstName
Listing 14-1
SQL Query
joining the Organizations, Students, StudentLessonInformation, and Lessons tables
We join the four tables, do some logic so that we don’t divide by zero when calculating the percentage test score, concatenate names in both Last Name, First Name and First Name Last Name format, and then exclude inactive students and lessons in our WHERE clause.
Connecting to and Transforming the Data
We are now ready to move to Power BI. We create a new report in Power BI Desktop and choose to get data
from SQL Server, as shown in Figure 14-4.
We enter the Server,5Database
, .and the Data Connectivity mode. Since this is a small data set, importing the entire query will work fine. For larger data sets, we could use DirectQuery, which does not load any data during development, but instead just loads the tables and columns. It then queries the data when used. We open the Advanced options and then paste in the query from Management Studio (shown back in Listing 14-1).
As is our standard practice, we Transform data and proceed to rename columns. Since we are only interested in the date and not the time, we change the type to Date
, as shown in Figure 14-6.
We add an index column for use in our visualization. Back in the Report Viewer example, we could use the .rdlc file to format the score as shown here:
This checks if the RawScore is numeric and, if so, multiples our PercentScore by 100 and rounds it to one decimal place. If not, it makes the value blank. In Power BI, it is easier to implement this as a custom Score column, as shown in Figure 14-7.
This takes the PercentScorecolumn
(which has a value like 0.86) and multiplies it by 100. Power BI is smart enough not to have an error if the value is null. In that case Score will be null as well.
Our last data task is to go to the Data screen and change the Date format of our date columns to Short Date, as shown in Figure 14-8.
Visualizing the Data
We are now ready to start creating our visualizations. Figure 14-9 shows both the final result and the selected card that shows the count of our Index column (renamed to say # of Students).
Note that the 333 value matches our query (Figure 14-3). We next create slicers for Most Recent Completion Date, Lesson, Organization, and Student. To get a Search box, we Get more visuals, enter “Search” in the box, and select the Text Filter visual from Microsoft. These are shown in Figures 14-10 and 14-11.
This allows you to search for a particular student.6 Figure 14-12 shows the result of searching for “Jim.”
Notice how the tooltip of the # of Lessons and Average Score shows up when we hover over a user, in this case Jimmy Buffett.7 Notice how the other visuals are updated as well with only the lessons, statuses, and detailed information associated with Jimi Hendrix and Jimmy Buffett.
Updating the Drill-Down Interactions
Our last task is to adjust what happens when we drill down
on particular lessons, students, or statuses. Figure 14-13 shows the default experience of “highlighting” the related visuals.
We have clicked on _Happy Lesson. The Student and Status visual are grayed out with the matching areas highlighted. This is sub-optimal to me at least. Instead, we’d like to see what students took that lesson
and what statuses are associated with that lesson. To get that behavior, we select the lessons visual, go to the Format tab, and click Edit interactions. We than click on the popup Filter button on each of the other visuals.8 This is shown in Figure 14-14. Note that the Table only has the filter option, so we don’t need to edit anything there.
Figure 14-15 shows the result. Notice how this is a much cleaner interface and only shows the data
associated with the _Happy Lesson we selected.
Summary
In this chapter, we transformed an older reporting approach into Power BI. We connected to a real-life SQL Server database, transformed our data with a custom column, updated data types, an index column, and by renaming our columns for clarity. We customized our data display format and then visualized our data with the normal mix of cards, slicers, charts, and tables. We added a Search control to allow the user to search for key data like the student and lesson names. We then saw how to change our drill-down interaction from highlight to filter, which I find preferable in most cases.