Actually using the new DataConnector for PowerBI
Tags: uncategorised, neo4j, powerbi
Published: 2020-02-19 09:33:05

---
title: Actually using the new DataConnector for PowerBI
published: true
date: 2019-02-06 10:45:50 UTC
tags: Uncategorised,Neo4j,PowerBI
canonical_url: 
---

After I’d written it – I realised my last post was perhaps not the most useful for those who really don’t care about the _how_ but want to know _what_ to do to use it. So this will follow the same deal as with the last post (over a year and a half ago!! WOW!).

Video version below if you want it:

<iframe src="https://player.vimeo.com/video/315612940" width="525" height="295" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>

## The Setup Steps

First – we’ve got to install PowerBI – now, I didn’t sign up for an account, but downloaded it from the [PowerBI website](https://powerbi.microsoft.com/en-us/get-started/), and installing was simple and quick.

We also need to have Neo4j running, and you can use Community _or_ Enterprise, it matters not – and we’ll want to put the ‘Movies’ dataset in there, so run your instance, and execute:

```
:play movies
```

## Add the Data Connector to Power BI

1. First – download the connector from the releases page (or build it yourself in VS) – you want the `Neo4j.mez` file.

Version 1: [https://github.com/cskardon/Neo4jDataConnectorForPowerBi/releases/tag/1.0.0](https://github.com/cskardon/Neo4jDataConnectorForPowerBi/releases/tag/1.0.0 "https://github.com/cskardon/Neo4jDataConnectorForPowerBi/releases/tag/1.0.0")

2. PowerBI looks for custom connectors in the `<USER>\Documents\Power BI Desktop\Custom Connectors` folder, which if it doesn’t exist – you’ll need to create. Once you have that folder, copy the `Neo4j.mez` connector there.

[![image](https://i1.wp.com/www.xclave.co.uk/wp-content/uploads/2019/02/image_thumb.png?w=525)](https://i0.wp.com/www.xclave.co.uk/wp-content/uploads/2019/02/image-2.png)

3. Nearly there – we just need to allow PowerBI to load the connector now – so, start up PowerBI and go to the Options dialog:

[![image](https://i0.wp.com/www.xclave.co.uk/wp-content/uploads/2019/02/image_thumb-1.png?w=525)](https://i0.wp.com/www.xclave.co.uk/wp-content/uploads/2019/02/image-3.png)

Once there, select the ‘Security’ option, and then under the Data Extensions header select the option allowing you to load any extension without validation or warning:

[![image](https://i1.wp.com/www.xclave.co.uk/wp-content/uploads/2019/02/image_thumb-2.png?w=525)](https://i1.wp.com/www.xclave.co.uk/wp-content/uploads/2019/02/image-4.png)

You’ll have to restart PowerBI to get the connector to be picked up – so go ahead and do that now!

## Lets Get Some Data!

Now – I know a lot of you will have been excited by the Pie Chart from the last post – now you can create your own!

With a new instance of PowerBI running, let’s select ‘Get Data’

[![image](https://i1.wp.com/www.xclave.co.uk/wp-content/uploads/2019/02/image_thumb-3.png?w=525)](https://i2.wp.com/www.xclave.co.uk/wp-content/uploads/2019/02/image-5.png)

We can now either search for ‘Neo4j’ or look in the ‘Database’ types:

![](https://xclave.co.uk/wp-content/uploads/2019/02/image-6.png)

Select `Neo4j`then press ‘Connect’ – aaaaand a warning!

![](https://xclave.co.uk/wp-content/uploads/2019/02/image-7.png)

Read it, ignore it – it’s up to you – but this is just to let you know that it’s still in Beta (I mean it’s only had one release so far!) Continue if you’re happy to.

Now you’re given the boxes to enter your Cypher and connection information – the text box for the Cypher field is a single line (ugh) – so if it’s a complicated query – you’re probably best of writing it in Sublime or similar (maybe even _Notepad!?!_). In this case, we can go simple:

MATCH (m:Movie) RETURN m;

Now, the other settings, if you’re running default settings – you can leave these, but obviously if you need to connect to `https` instead of `http` change it in the `scheme` setting. I’ve filled in my display with the defaults:

![](https://xclave.co.uk/wp-content/uploads/2019/02/image-8.png)

When you press OK, you get the Login dialog, _if _you are anonymously connecting, then select Anonymous, else – fill in your username / password.

![](https://xclave.co.uk/wp-content/uploads/2019/02/image-9.png)

Press ‘Connect’, and PowerBI will connect to your DB and return you back a list of ‘Record’:

![](https://xclave.co.uk/wp-content/uploads/2019/02/image-10-1024x774.png)

We’ll want to ‘Edit’ this, so press ‘Edit’!

When the Power Query Editor opens press the expand column button at the top of the ‘m’ column:

![](https://xclave.co.uk/wp-content/uploads/2019/02/image-12-1024x515.png)

Ooooooh, ‘tagline’, ‘title’ and ‘released’ — our movie properties! For this, I would turn off the ‘use original column name as prefix’ checkbox, leave them all selected and press OK.

![](https://xclave.co.uk/wp-content/uploads/2019/02/image-13-1024x347.png)

**Data!!**

Now, let’s ‘Close & Apply’ our query – NB – if you look in the ‘Applied Steps’ section, you can see we only have 2 steps, ‘Source’ and ‘Expanded m’

![](https://xclave.co.uk/wp-content/uploads/2019/02/image-14.png)

Whilst PowerBI applies it just think of the Pie charts that lie ahead of us:

![](https://xclave.co.uk/wp-content/uploads/2019/02/image-15.png)

When that dialog disappears, we’re good to go! On the right you’ll see a ‘Fields’ section, and you should see something like this:

![](https://xclave.co.uk/wp-content/uploads/2019/02/image-16.png)

So, the moment we’ve all waited for…

## Let’s Pie Chart

Select ‘Pie Chart’ from the Visualizations section:

![](https://xclave.co.uk/wp-content/uploads/2019/02/image-17.png)

Once it’s in your display – select it and drag the ‘released’ field from the `Query1` to the ‘details’ field, and then title to the ‘values’ field:

![](https://xclave.co.uk/wp-content/uploads/2019/02/image-18.png)

Your chart should look something like this now:

![](https://xclave.co.uk/wp-content/uploads/2019/02/image-19.png)

So let’s max size it, and mouse over it, now we can see:

![](https://xclave.co.uk/wp-content/uploads/2019/02/image-20.png)

But we can also drag ‘title’ on to the Tooltips field like so to get the First (or last) movie in that group:

![](https://xclave.co.uk/wp-content/uploads/2019/02/image-21.png)

## What does a query look like under the covers?

Some of us like visual, some like code, the last time we tried this – our query was 20 lines long – our new query though – that’s just 5!

```
let Source = Neo4j.ExecuteCypher("MATCH (m:Movie) RETURN m;", "http", "localhost", 7474), #"Expanded m" = Table.ExpandRecordColumn(Source, "m", {"tagline", "title", "released"}, {"tagline", "title", "released"})in #"Expanded m"
```

Which is much nicer.

## Hey hey! It’s Beta!

The Data Connector approach gives a much nicer way to query the database, it strips out a lot of the code we have to write, and hopefully makes the querying easier.

BUT – I am _not_ a PowerBI expert – is this the right way to do this? Are there improvements? Some hardcoded queries we should have there? Let me know – do a PR – it’s all good!