using microsoft power query to analyze facebook data
DESCRIPTION
Yesterday I was tipped off about a new add-on for Excel 2013 that Microsoft have just released called Power Query, so I had to take a look at it. As the name hints, this is the data query function on steroids, and it looks great. The following walkthrough is an example of what I did.TRANSCRIPT
© 2013. All rights reserved.
USING MICROSOFT POWER QUERY TO
ANALYZE FACEBOOK
Microsoft Excel | Power Query | Power View
Yesterday I was tipped off about a new add-on for Excel 2013 that Microsoft have just released called Power Query, so I had to take a look at it. As the name hints, this is the data query function on steroids, and it looks great.
The following walkthrough is an example of what I did.
© 2013. All rights reserved.
DOWNLOADING & INSTALLING POWER
QUERYThe first step in the process is to download Power Query.
© 2013. All rights reserved.
Downloading &
Installing Power
Query
Power Query is easy to find. I just did a Bing search and found it right away on the Microsoft Download Center:
http://www.microsoft.com/en-us/download/details.aspx?id=39379
© 2013. All rights reserved.
A QUICK TOUR OF POWER QUERY
As I mentioned before, Power Query is an extended version of the Data Query function that you may have used in Excel in the past, except the data sources that it is able to query so much better.
In this section we will look at what the Power Query Add-In provides us.
© 2013. All rights reserved.
A Quick Tour of
Power Query
When you install Power Query, you will notice a new ribbon bar has been added.
© 2013. All rights reserved.
A Quick Tour of
Power Query
You can query from files… especially interesting here is the From folder option that allows you to query the file system and return back file information.
© 2013. All rights reserved.
A Quick Tour of
Power Query
You can query other databases… including Oracle, DB2, MySQL, PostgreSQL and Teradata databases.
© 2013. All rights reserved.
A Quick Tour of
Power Query
And you can query from other sources… including SharePoint Lists, Active Directory, Big Data datasources, and Facebook.
All of these additional data sources can be queried and combined into data mashups… how cool is that.
© 2013. All rights reserved.
USING POWER QUERY TO QUERY YOUR
FACEBOOK FRIENDSNow that we have Power Query installed, its time to start using it to grab some of the data.
In this example I will show how you can use Power Query to query your Facebook account.
© 2013. All rights reserved.
Using Power Query
to Query your
Facebook Friends
To start off, select the POWER QUERY ribbon bar within Excel and select the From Facebook option from the From Other Sources menu button dropdown.
© 2013. All rights reserved.
Using Power Query
to Query your
Facebook Friends
This will open up the Facebook options form.
If you want to mine information on another user, then you can type in their username, or in this case, use me to access your own personal data.
© 2013. All rights reserved.
Using Power Query
to Query your
Facebook Friends
In the Connection name you can select the type of information that you want to query from Facebook. In this case I want to find all of my friends.
© 2013. All rights reserved.
Using Power Query
to Query your
Facebook Friends
Once you have selected the source and type of data that you want to query then click the OK button.
© 2013. All rights reserved.
Using Power Query
to Query your
Facebook Friends
Since this was the first time that I queried Facebook, it is going to ask me to sign in.
© 2013. All rights reserved.
Using Power Query
to Query your
Facebook Friends
It will ask you for your Facebook credentials.
© 2013. All rights reserved.
Using Power Query
to Query your
Facebook Friends
Once you have stored your Facebook credentials within Power Query, you won’t have to do this any more.
Note: if you want to update or remove these credentials, just click on the Data Source Settings button within the Machine Settings group, and you will be able to delete the username and password.
© 2013. All rights reserved.
Using Power Query
to Query your
Facebook Friends
Power Query will now return back a subset of the data from Facebook as a test query.
Notice though that some of the data shows up as a green hyperlink like the data in the object_link field. This means that there is more data beneath.
© 2013. All rights reserved.
Using Power Query
to Query your
Facebook Friends
Double clicking on the link will drill down into that data.
© 2013. All rights reserved.
Using Power Query
to Query your
Facebook Friends
You can keep on drilling down into the record to navigate through the data.
© 2013. All rights reserved.
Using Power Query
to Query your
Facebook Friends
If you want to expand out any of the data at the lower levels and include it in your query, then lick on the expansion icon in the top right of the field name header, and you will be able to see all of the available sub-fields.
Select the fields that you want to include and click OK.
© 2013. All rights reserved.
Using Power Query
to Query your
Facebook Friends
Now your query will start to flatten out and you can use the data.
Once you have finished manipulating the query, click the Done button.
© 2013. All rights reserved.
Using Power Query
to Query your
Facebook Friends
The query will now be available within Excel as a worksheet.
© 2013. All rights reserved.
USING POWER VIEW TO ANALYZE YOUR
FACEBOOK FRIENDSOnce you have queried Facebook using Power Query, you will probably want to visualize it. The best tool for that is Power View.
In this example I will show how to use Power View to quickly create a dashboard analysis.
© 2013. All rights reserved.
Using Power View
to Analyze your
Facebook Friends
To start creating the Power View dashboard, select the query data within Excel and then click on the Power Viewbutton within the Reports group of the Insert ribbon bar.,
© 2013. All rights reserved.
Using Power View
to Analyze your
Facebook Friends
This will open up the blank Power View canvas with all of the query fields available within the field explorer.
© 2013. All rights reserved.
Using Power View
to Analyze your
Facebook Friends
The first query that I will create is a simple analysis of my friends. In this case the gender breakdown. To do this I just selected the object_link_gender field and added it to my reporting canvas.
© 2013. All rights reserved.
Using Power View
to Analyze your
Facebook Friends
Then I converted the Table into a Matrix by selecting Matrix from the Table button on the DESIGN ribbon bar.
© 2013. All rights reserved.
Using Power View
to Analyze your
Facebook Friends
To count the records I then added the object_link_genderfield to the VALUES group in the report designer panel.
© 2013. All rights reserved.
Using Power View
to Analyze your
Facebook Friends
Since this element is a Matrix, I can now change it to a chart. From the Other Chart options in the DESIGNribbon bar, select the Pie option.
© 2013. All rights reserved.
Using Power View
to Analyze your
Facebook Friends
After adding a title, and another card view to the dashboard I have a quick summary of my Facebook friends.
© 2013. All rights reserved.
USING POWER QUERY TO ANALYZE YOUR
FACEBOOK FEEDSAnalyzing your friends on Facebook is nice, but something that is even more interesting is to analyze the Facebook Feeds. Power Query allows you to download your complete Facebook feed history so that you can take a walk down memory lane.
In this example I will show how you can use Power Query to view you Facebook Feed activity.
© 2013. All rights reserved.
Using Power Query
to Analyze your
Facebook Feeds
To start off, select the POWER QUERY ribbon bar within Excel and select the From Facebook option from the From Other Sources menu button dropdown.
In the Connection name select the Feed option.
© 2013. All rights reserved.
Using Power Query
to Analyze your
Facebook Feeds
The Feed query from Facebook returns a little more information than the Friends query…
© 2013. All rights reserved.
Using Power Query
to Analyze your
Facebook Feeds
But we need a little more for this analysis. Expand out the object_link field.
© 2013. All rights reserved.
Using Power Query
to Analyze your
Facebook Feeds
This will give us the name of person that is posting to our timeline
© 2013. All rights reserved.
Using Power Query
to Analyze your
Facebook Feeds
Expand out the status_type field.
© 2013. All rights reserved.
Using Power Query
to Analyze your
Facebook Feeds
Expand out the object_id field.
© 2013. All rights reserved.
Using Power Query
to Analyze your
Facebook Feeds
And finally, expand out the shares field.
© 2013. All rights reserved.
Using Power Query
to Analyze your
Facebook Feeds
After manipulating the query, click on the Done button to transfer it to the Excel workbook.
© 2013. All rights reserved.
Using Power Query
to Analyze your
Facebook Feeds
Now our query is almost ready to use. The only problem is that I want to analyze this data by the date, and the create_time field is a little too granular.
© 2013. All rights reserved.
Using Power Query
to Analyze your
Facebook Feeds
So add a new column to the query for the Year, and use a little bit of string manipulation to extract the year from the create_time field. (Normally I would use the Year() function, but it doesn’t like the Facebook format of the date/time)
© 2013. All rights reserved.
Using Power Query
to Analyze your
Facebook Feeds
Add another field for the Month.
© 2013. All rights reserved.
Using Power Query
to Analyze your
Facebook Feeds
And finally, add a Period column that combines the year and the month.
© 2013. All rights reserved.
Using Power Query
to Analyze your
Facebook Feeds
Now, select the query and click on the Power View button within the Reports group of the INSERT ribbon bar.
© 2013. All rights reserved.
Using Power Query
to Analyze your
Facebook Feeds
Now create a Matrix Table to analyze the activity by year.
I didn’t really use Facebook that much in 2007 & 2008 I guess…
© 2013. All rights reserved.
Using Power Query
to Analyze your
Facebook Feeds
Now create a more detailed matrix field by combining the Year and the month.
© 2013. All rights reserved.
Using Power Query
to Analyze your
Facebook Feeds
Then convert the table to a Bar Chart. This allows me to see where the peaks by month are for my feed posts –October was the obvious winner in general because that’s my birthday month, although February of 2009 must have been a power friending month…
Additionally, add a line graph to the dashboard, using the Period field that you created to show the history over time.
Very cool.
© 2013. All rights reserved.
ANALYZING YOUR FACEBOOK FRIENDING
HISTORYSomething else that I thought would be interesting to analyze is the actual Feed content from Facebook. Since the query returns the activity header, why not analyze the type of feed.
In this example I will show how to analyze the feeds to track friending activity.
© 2013. All rights reserved.
Analyzing Your
Facebook Friending
History
To track friending posts, add another column to the Feed query and mark anything that finishes with “are now friends.”.
© 2013. All rights reserved.
Analyzing Your
Facebook Friending
History
Now that we have that additional piece of data we can create a simple Power View dashboard showing the friending activity my month.
Very cool.
© 2013. All rights reserved.
ANALYZING FEED ACTIVITY BY APPLICATION
Hidden in the Feed query are other details that are interesting to visualize. One of them is the application type.
In this example I will show a simple analysis of the Facebook feed to track the applications.
© 2013. All rights reserved.
Analyzing Feed
Activity by
Application
In this example I created a simple dashboard using Power View. The cool think here is that the icon field shows as an image – Power View automatically recognizes it, and if we add it as a field then we can see all of the posts broken out to source.
© 2013. All rights reserved.
Analyzing Feed
Activity by
Application
Filtering out the data by year shows us what was hot at the time.
© 2013. All rights reserved.
Analyzing Feed
Activity by
Application
Also, by creating a date hierarchy in the report, we can drill down by year down into the monthly periods for more information.
I don’t know why my dog – “Barney Fife” was posting so much in 2012… I need to investigate that more.
© 2013. All rights reserved.
SUMMARY
Power Query is a great new tool to take advantage of. Using it to query the less structured data like Facebook is just the starting point. Once you have played around with it a little you may want to try creating data mash-up’s by combining the data from one data source with another.
Give it a go and drop me a note when you create something cool.
http://slideshare.net/murrayfife/presentations
Murray FifeMicrosoft MVP