Andy Cross edited this page Oct 26, 2015 · 7 revisions
Clone this wiki locally

At Elastacloud, we built an SDK for controlling PowerBI with C#. It's key goals are to simplify data access and authentication, allowing easy and rapid access to core PowerBI assets. We want developers to have an experience with PowerBI that is first class and help unlock the innate creative potential of developers. So many developers find getting their data across to end users in a clear way a difficult challenge and we think PowerBI is in a unique position to solve this. Unlocking the delivery of data and coupling that with the easy and extensible visualizations puts the power to innovate in a developers hands.

When we looked at the PowerBI toolchain we saw a few places that we wanted to help. We created the Calendar visual and continue to participate in the active community growing around the extending the variety of visuals available in PowerBI.

Then we looked at the other side, how to get data into PowerBI and control it in an automated fashion. There's a really great API for that, but all the samples require the crafting of REST requests yourself. That's not the hardest challenge in 2015, but it does slow down the development cycle which is a killer for creativity.

We set out with a simple challenge; create datasets and tables around .net objects (plain old clr objects - POCOs) and let a developer with an existing solution get creative with their data immediately. No intermediate EventHubs. No staging storage. A collection of class instances in memory, a PowerBI account to add them to ... voila!

To get started, we chose myget.org to host our build services and provide continuous integration and build for our solution. We chose nuget.org as the way to distribute our work.

For authentication, PowerBI uses Common Concent in Azure AD. We decided to encapsulate AzureAD authentication code to make it easy for developers to get start, but also allow it to be swapped out, in case the dev.

We call this solution bisharp.

So to get started, firstly install the nuget package;

install-package bisharp

Then create an instance of a PowerBiAuthentication in order to wrap up all the auth details, and it'll prompt you to enter your AzureAD credentials. It's worth noting that we never see or share these credentials; they go straight to Microsoft and always stay safe.

Once we've created that PowerBiAuthentication we just pass that to a client and use it to do some work. That client can do things like create and manage datasets, add rows to that dataset, manage dashboards and groups.

So imagine you have a class that details stuff about planes and flights.

public class FlightInfo
        public int Altitude { get; set; }
        public int GroundSpeed { get; set; }
        public string Model { get; set; }
        public string Manufacturer { get; set; }
        public double Latitude { get; set; }
        public double Longitude  { get; set; }

Then we can really easily add instances of this class to a dataset that we can create on the fly;

var pbi = new PowerBiAuthentication("{your client ID}");
var flightData = "flightData";
var dsClient = new DatasetsClient(pbi);
var result = dsClient.Create(flightData, true, typeof(Classes.FlightInfo)).Result;
var flightDataDatasetId = result.id;

dsClient.AddRows(flightDataDatasetId, typeof(FlightInfo).Name,new TableRows<FlightInfo>()
                rows = new List<FlightInfo>() { new FlightInfo()
                    Altitude = 10000,
                    GroundSpeed = 429,
                    Heading = 322,
                    Manufacturer = "Airbus",
                    Model = "A330",
                    Latitude = 51.5008d, 
                    Longitude = -0.1247d
                } }

How easy is that? Now you can use the really powerful features of PowerBI to build really powerful visualisations of your data.

Flight Data report

But that's not all. You can use this library in your web applications to really easily embed your PowerBI dashboards in your own solution.

So imagine you build up that Flight data report into a dashboard and it looks a little like this:

Flight Data Dash

If you want that on your web app, and you don't want to have to reinvent the wheel... you can use bisharp!

Flight Data Dash

Plug in AzureAD for single sign on, hit the link "PowerBI" in the header:

Flight Data Dash

And there you go.

All of this is open source. All of this is provided as samples. All of this is ready for you to take PowerBI to the next level.