Unwrapping SteemSQL JSON columns using Power BI – 10 Easy StepssteemCreated with Sketch.

in #utopian-io9 years ago

Have you struggled to extract data from the JSON columns in SteemSQL when analyzing the Steemit Blockchain database?

Maybe, like me you are not proficient enough in SQL to run the query directly. Well to the rescue is the query editor in Power BI.

The Power BI Query editor runs on a language known as M. However, Power BI is a self-service business intelligence package which means that you should be able to transform data without the need to know code.

In this tutorial I will show you step by step how you can use Power BI to connect to SteemSQL database and parse the active_votes column in the Comments tables.

Step by Step

Step 1: Open Power BI and Select Get Data from SQL database
3.png

Step 2: In the query editor window enter the following
Server: sql.steemsql.com
Database : DBSteem
4.png

Step 3: Select Advanced options in the query editor to open the SQL code box. Copy the following code to the box and select OK

   SELECT
     author,
     net_votes,
     children,
     Category,
     Depth,
     active_votes
      FROM
    Comments WITH (NOLOCK)
   where    created >= CONVERT(datetime,'11/01/2017')
   AND created< CONVERT(datetime,'11/02/2017')

5.png

The query editor will now run and you will be returned with the table of data containing the selected columns from the Comments table between the set dates.

Step 4 : You will then be given a preview of your data. Select Edit
6.png

This will load the data into the query editor for further transformation.

Step 5: Select the column active_votes and in the transform ribbon select parse JSON
7.png

This will convert your active_votes column to a list

Step 6: Expand the list to new rows by click on the cross-hair in the column header

8.png

This will convert your list to Records.

Step 7: Expand the Records again by clicking on the cross-hair in the column header. Uncheck user original column name as prefix and select ok.

9.png

You will now be returned with the JSON parsed into columns in your data set.

10.png

Step 8: Ensure that your new columns of data are set to the correct data type. Select any columns that require changing and from the transform ribbon you can select the data type

11.png

Step 9: Rename your query. You can do this on the right side of your screen under Query Settings and Name

12.png

Step 10: Carry out any further transformations you require on the data before loading it into the data model for further analysis with DAX or visual presentations.

Final Code

The final M code produced by Power BI is

 let
 Source = Sql.Database("sql.steemsql.com", "DBSteem", [Query="SELECT#(lf)    author,#(lf)    
 net_votes,#(lf)    children,#(lf)    Category,#(lf)    Depth,#(lf)    active_votes#(lf)        FROM#(lf)    
 Comments WITH (NOLOCK)#(lf)where    created >= CONVERT(datetime,'11/01/2017')#(lf)AND 
  created< CONVERT(datetime,'11/02/2017')#(lf)"]),
  #"Parsed JSON" = Table.TransformColumns(Source,{{"active_votes", Json.Document}}),
  #"Expanded active_votes" = Table.ExpandListColumn(#"Parsed JSON", "active_votes"),
  #"Expanded active_votes1" = Table.ExpandRecordColumn(#"Expanded active_votes", 
  "active_votes", 
  {"voter", "weight", "rshares", "percent", "reputation", "time"}, {"voter", "weight", "rshares", 
  "percent", 
  "reputation", "time"}),
  #"Changed Type" = Table.TransformColumnTypes(#"Expanded active_votes1",{{"voter", type 
  text}})
  in
  #"Changed Type"

Invitation

I would invite someone with SQL knowledge to write this query in SQL and share it below

If you have struggles with extracting this data from the database and you have found this tutorial of use, please do comment below.

** I am part of a Steemit Business Intelligence community. We all post under the tag #BIsteemit. If you have an analysis you would like carried out on Steemit data, please do contact me or any of the #bisteemit team and we will do our best to help you...

You can find #bisteemit on discord https://discordapp.com/invite/JN7Yv7j
**



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

Interesting, very helpful. The first time that I heard of Power BI...

step by step detail! i will learn this! thank you for sharing!

Hey @paulag I am @utopian-io. I have just upvoted you!

Achievements

  • You are generating more rewards than average for this category. Super!;)
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x

Very useful ..thank for share

Thank you for sharing these issues with us

Outstanding post and narrative. Thank you for sharing!

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Well you cant get much clearer than this. Again, I really have no excuses not to get my arse in gear and tackle PowerBI.

Thank you for 'my' tutorial! :)

you are most welcome :-)

Coin Marketplace

STEEM 0.04
TRX 0.33
JST 0.103
BTC 64098.49
ETH 1860.18
USDT 1.00
SBD 0.39