Getting Started with the New Power BI Activity Log API

When the new Power BI service activity logging API was announced over the holidays, I was intrigued and anxious to start working with it. I’ve had some experience with report usage monitoring using the existing Office logs and usage metric reports that do provide some useful information but can be a chore to use. Activity monitoring and troubleshooting with the new logging API is focused entirely on Power BI tenant events like dashboard, interactive and paginated reports views, deployments, errors and data refresh events. This should be easier than before, enabling admins to be more proactive by tracking usage patterns. In a short series of blog posts, I’ll demonstrate how to build a complete activity logging and reporting solution for your entire Power BI tenant. In this first post of the series, we’ll just get started with the basics by capturing just a few log events for a brief window of activity and surface them in a simple report.

Before we get started,

a brief history lesson is on order:


When the Power BI cloud-based service was initially offered back in 2013 as a feature extension to Office 365, it used SharePoint Online as the storage architecture. Some additional logging events were added to the existing and numerous Office 365 events catalog. It has always been cumbersome to find relevant reporting information amid all of the other noise in these logs. Components of the Power BI back-end services have since been migrated into a more specialized service infrastructure but the activity logging has remained in Office 365 until December of 2019. The Office logs required special privileges within the Office tenant and produced volumes of event data related only to folders, files and Office documents.

The new Power BI Activity Log API is specially-suited and optimized just for Power BI. By contrast, it will be much easier to identity and track relevant service and user activity for workspaces, apps, dashboards, interactive Power BI reports and paginated reports in the Power BI service.

I envision that my production-scale logging solution will use an orchestration tool like Azure Data Factory to iterate over historical activity logs, store log files to Azure Data Lake Storage and then incrementally update a Power BI data model for reporting and analysis. This first example will use PowerShell script manually executed from my desktop.

PowerShell Me, Baby

The new Get-PowerBIActivityEvent commandlet is added to the Microsoft Power BI Management library. Install the latest version to gain access to the activity logs.

In my project, the first step is to open and run the PowerShell ISE as a local administrator. To installed the latest Power BI Management library locally, I execute this code :

Install-Module -Name MicrosoftPowerBIMgmt.Admin

I need to sign-in to my Power BI tenant with a service or user account that has tenant admin privileges. This code opens a standard login dialog and prompts for a user name and password, populating a Credential type object variable used to open a connection to the Power BI service:

$Cred = Get-Credential

Connect-PowerBIServiceAccount -Credential $Cred

In the Power BI product team’s Developer blog, Senior Program Manager Kay Unkroth explains that the Get-PowerBIActivityEvent commandlet can be called with date/time parameters to include only one day at a time. This line requests all activity on Junuary 5th, 2020, caching the activity log information as a JSON structure:

$activities = Get-PowerBIActivityEvent -StartDateTime ‘2020-01-05T00:00:00.000’ -EndDateTime ‘2020-01-05T23:59:59.999’

Finally, I write the log contents to a local file using this code:

$activities | Out-File -FilePath C:\Temp\RSActivityLog.json

Importing this file into Power BI Desktop produces the following simple table:

A couple of important things to point out

The API is optimized to handle large numbers of events. As such, it is limited to return records for a range of time up to one full day using the StartDateTime and EndDateTime parameters. The web service returns a continuation token return parameter to let you know if there is more data beyond a fixed frame size that will typically return about 5,000 to 10,000 records.

Incidentally, I’ve played with a few different file formats. JSON is by far the most flexible format but you may not get all the key/values you want just by consuming the results right out-of-the-box and without parsing all the nested levels. In Kay’s article, he uses the ConvertTo-JSON directive to flatten the native JSON document into a more conventional colon-delineated log flat file with named key/value pairs. Using this method, I was able to get more field information that those that apparently slipped through the cracks from the JSON document. Although, I had to massage the output a bit and then transform the rows into columns using some fancy pivot dancing in Power Query.

This simple report

is a first effort showing records for a short time frame. I’ve produced a single table with some recognizable grouping and slicing attributes but we can do considerably more. Using these fields, I analyze activities for only dashboard , Power BI or paginated report views. We can filter by user, object type, operation type, the web browser or devices used to view content, type of workload or the containing workspace.

In a fully-fleshed-out data model, some of the attributes might exist as separate dimension/lookup tables. But, this is enough for now.

Post Conclusion

Please share your questions and your own experience with the activity logging API, and watch for subsequent posts about tenant monitoring and activity management solutions.

Paul Turley

Paul Turley

Microsoft Data Platform MVP, Principal Consultant for 3Cloud Solutions Specializing in Business Intelligence, SQL Server solutions, Power BI, Analysis Services & Reporting Services.

10 thoughts on “Getting Started with the New Power BI Activity Log API

  1. Thanks for this article. Did you ever get the chance to realize your vision of having this work with Azure Data Factory?

  2. Hi Paul,
    I built a PowerShell script sample based on your example (I’m using dynamic StartDateTime & EndDateTime values..). The whole process seemed to work fine and I was able to export JSON file result and then consume data in Power BI Desktop. That’s fine for testing. Now my question is :I would like to use a Service Principal mode of authentication instead, so I could run it in a Task Scheduler process avoiding to go through pop-up each time. Do you know if that is possible with this PS context and if so, where I could get a sample.

    Thanks

    1. Hi Denys, I am working on a similar project and curious to know if you were able to figure out how to automate the authentication? I have an Azure AD app that I am using to access the PowerBI REST API endpoints like reports, workspaces etc.Hoping to utilize a similar workflow in this case as well.

  3. Hi Paul,
    Thanks for sharing your infos on Powershell. Always deeply appreciated;) As you may already be aware, Microsoft has included a “Try it” playground option on its official Power BI REST API wiki website.
    I found it a very helpful tool for testing & quick demo.

    I don’t know if I missed something but I tried the Get Activity Events option sample with startDateTime: 2020-04-16T00:00:00 and endDateTime: 2020-04-16T23:59:59 parameters. Clicking on Run it button doesn’t seem to generate a proper url method format. Results displays 401 error! Every other methods run fine displaying expected result. So I assume something’s wrong in url format.

    After filling the input parameters I end up with
    https://api.powerbi.com/v1.0/myorg/admin/activityevents?startDateTime='2020-04-16T00%3A00%3A00.000'&endDateTime='2020-04-16T23%3A59%3A59.999
    instead of:
    https://api.powerbi.com/v1.0/myorg/admin/activityevents?startDateTime='2020-04-16T00:00:00'&endDateTime='2020-04-16T23:59:59

    The “:” character is replaced with “%03A” on Power BI REST API generated url in GET input text field. I may be wrong but it doesn’t seem right….

    BTW I managed to create a dotnet core 3.1 web api service (+ Swagger | Swashbuckle doc generation option) which does a very good job. I’m able to use most of defined GET Power BI REST API methods options directly through url (with id parameters included when needed…) which returns result in JSON format. All I have to do is simple quick modeling transformation through M Query to clean it up et voila.
    So the only missing option for me at this stage is the Get Activity Event method… I know I could use Powershell, but I’d wish to integrate it in Web api service. Any hints on how to properly use ISO time format would be deeply appreciated. Thanks.

  4. Great post.

    I run the command below and it returns the expected JSON response structure, however it doesn’t return any data. I have all of the auditing and logging options enabled in the “Audit and usage settings”, so I should be logging events. I tried different days and no luck.

    Command:

    $activities = Get-PowerBIActivityEvent -StartDateTime ‘2020-02-26T00:00:00’ -EndDateTime ‘2020-02-26T23:59:59’ | ConvertFrom-Json

    $activities | Out-File -FilePath C:\Temp\PowerBIAuditLogs\test.csv

    Any ideas why I’m not returning data in the response? All I get back is “{}” with no data for the fields.

  5. What will the ID come back as for Power BI Embedded when running reports? The service principal or the actual user id/email?

  6. Nice tutorial, thanks.
    Have you had any issues with the following error: “Login first with Login-PowerBIServiceAccount”? I can’t get the Activities. Also tried Login-PowerBIServiceAccount.

Leave a Reply

Discover more from Paul Turley's SQL Server BI Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading