How to: Generate power query for Odata

Some instances require a specialized Odata connection with an Advanced Transformation.

Instructions

Copy the script below, updating the Tenant ID and Module Name. (Lines 5 & 13)

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 let EntitiesPerPage = 1000, GetEntityCount = () => let Json = Json.Document(Web.Contents("https://core.stratawise.com/odata/350/MA@POU", [Query=[#"$count"="true"]])), Count = Json[#"value"] in Count, GetPage = (Index) => let Skip = Text.From(Index * EntitiesPerPage), Top = Text.From(EntitiesPerPage), Json = Json.Document(Web.Contents("https://core.stratawise.com/odata/350/MA@POU", [Query=[#"$skip"=Skip, #"$top"=Top]])), Value = Json[#"value"] in Value, EntityCount = List.Max({ EntitiesPerPage, GetEntityCount() }), PageCount = Number.RoundUp(EntityCount / EntitiesPerPage), //1, PageIndices = { 0 .. PageCount - 1 }, Pages = List.Transform(PageIndices, each GetPage(_)), Entities = List.Union(Pages), Table = Table.FromList(Entities, Splitter.SplitByNothing(), null, null, ExtraValues.Error) in Table

 

  1. Connect to through the existing Odata connection provided through the export prompt in the module grid.

  2. Select Transform Data.

     

  3. Select Advanced Editor.

     

  4. Paste the updated script from above and select Done.

  5. Select the icon at the top of the data set to expand.

     

  6. Then OK.

     

  7. Select Advanced Editor again.

  8. Copy the resulting script to a text editor and replace “column1.“ with ““ (nothing).

  9. Paste the updated script in and validate the resulting columns appear correct.