Wednesday, January 31, 2018

How to retrieve OData v4 fast in Power BI

I recently blogged about how Power BI has a bug which ignores the select statements when querying an OData v4 endpoint. Even though the columns would include any data, it still bugged me so much that I wanted to find a way around it.

Turns out that’s much easier than you would expect.

I recently explored some of the different data loading capabilities in PBI, and it turns out that there’s a Json.Document function which allows you to handle OData at an even lower level.

So what I did was take my original uri and query string: https://<org>.api.crm4.dynamics.com/api/data/v8.2/opportunities?$select=name

Then I put it into a Json.Document(Web.Contents())

And voila, this is the result

image

Navigating into that list, you can then right click the column and select “To Table”. This will present you with a table of records ready to be exploded:

image


So, time to do a little speed testing

Using: = OData.Feed("https://<org>.api.crm4.dynamics.com/api/data/v8.2/opportunities?$select=name")

Screenshot_20180131-160714

Using: = Json.Document(Web.Contents("https://<org>.api.crm4.dynamics.com/api/data/v8.2/opportunities?$select=name"))

Screenshot_20180131-160738


Enough said?

5 comments:

  1. How did you put it into the JSON.Document...what were your steps for a newbie?

    ReplyDelete
    Replies
    1. First you have to generate an OData query. If you haven't spent extensive time building queries before I recommend looking into the OData query builder created by Jason Latimer https://github.com/jlattimer/CRMRESTBuilder

      After you have a valid OData url then you can create a new blank query in Power BI. Then, click on the advanced editor, and add the following:
      let
      Source = Json.Document(Web.Contents("your-url-inside-here-do-not-remove-quotation-marks")
      in
      Source


      Finally, drill into the list and expand the way you want to use the data. See my other blog post for how to expand Dynamics data from a Json.Document here: http://www.crmviking.com/2018/01/dynamic-option-sets-in-powerbi.html

      Delete
  2. Tried this out and seems to be quick, but does not seem to work for lookup fields. Lookups error out and you cannot access even the associated guid...or maybe I'm doing it wrong...

    ReplyDelete
    Replies
    1. Not sure what you're doing, but I do get lookup ids when I use this. Joins and expands needs to be done manually since Web.Contents doesn't utilize the ODatav4 capabilities.

      Delete