Skip to content

Instantly share code, notes, and snippets.

@yuhgto
Forked from petrsvihlik/GitHub-GraphQL-PowerBI.m
Last active February 27, 2024 16:29
Show Gist options
  • Star 18 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save yuhgto/9d2d69aa1038954c1b8e0488cca290c2 to your computer and use it in GitHub Desktop.
Save yuhgto/9d2d69aa1038954c1b8e0488cca290c2 to your computer and use it in GitHub Desktop.
Outdated – Loading GraphQL data (monday.com API v2) into PowerBI
// Playing around with a PowerBI query to pull data from monday.com into PowerBI
// This can come in handy when building PowerBI reports that utilize GraphQL endpoints for loading data.
let
Source = Web.Contents(
"https://api.monday.com/v2",
[
Headers=[
#"Method"="POST",
#"Content-Type"="application/json",
#"Authorization"="<your_personal_token_here>"
],
// Notice the quote escaping here
Content=Text.ToBinary("{""query"": ""{ boards (ids: <your board ID here>) { items { name id column_values (ids:["<your column id here>"] { id title value } } } }""}")
]
),
#"JSON" = Json.Document(Source)
in
#"JSON"
@paulosoaresf
Copy link

Hey, @yuhgto thanks for providing the code. I'm getting a 500 error when I try to use it on PBI. Any thoughts? Token and board Id looks fine.

@holarenola
Copy link

Hi @yuhgto how do we address the error mentioned in the previous comment?

@llelong
Copy link

llelong commented Nov 2, 2023

Hi @paulosoaresf, @yuhgto
500 errors occur from Monday if query have error.
If you're using the ids:[""], GraphQL require the Column name to be surounded by double-quotes,
In order to amend double quotes in the M query, you have to use ""
Hence, the ids looks like ids:["""", """"]

@yuhgto
Copy link
Author

yuhgto commented Nov 2, 2023

Hey folks – I'm marking this as outdated as it does not use our updated cursor pagination. I'm not a deep PowerBI expert, so I am not 100% sure how to implement it in PowerBI.

If anyone wants to fork this and connect it to the new items_page object, be my guest! An explanation about cursor pagination is here.

@hmbouk
Copy link

hmbouk commented Jan 4, 2024

@yuhgto I used your query as a starting point to work through building queries using the cursor pagination. For anyone interested, have a look here https://gist.github.com/hmbouk/b5712f8d4639eb85328bf4828b402284 and here https://community.monday.com/t/using-power-bi-to-retrieve-boards-using-cursor-based-pagination/70535.

My approach has limitations and maybe someone can improve on what I came up with.

@jscortesgh
Copy link

@yuhgto I used your query as a starting point to work through building queries using the cursor pagination. For anyone interested, have a look here https://gist.github.com/hmbouk/b5712f8d4639eb85328bf4828b402284 and here https://community.monday.com/t/using-power-bi-to-retrieve-boards-using-cursor-based-pagination/70535.

My approach has limitations and maybe someone can improve on what I came up with.

Dear hmbouk, on your approach is possible to bring also the group of each item?

@hmbouk
Copy link

hmbouk commented Jan 12, 2024

@yuhgto I used your query as a starting point to work through building queries using the cursor pagination. For anyone interested, have a look here https://gist.github.com/hmbouk/b5712f8d4639eb85328bf4828b402284 and here https://community.monday.com/t/using-power-bi-to-retrieve-boards-using-cursor-based-pagination/70535.
My approach has limitations and maybe someone can improve on what I came up with.

Dear hmbouk, on your approach is possible to bring also the group of each item?

@jscortesgh Unfortunately, when I added the group to the query, the data returned couldn't be transformed into a set of rows with the group as a new column. What I tested and found worked well was to duplicate the Get_1stPage and Get_RemainingPages. I called them Get_1stPageGroup and Get_RemainingPagesGroup. Then I modified the query to look like this -> MondayQuery3 = ") {items_page(limit: 100) {cursor items {id group {title} }}}}""}",

Also, duplicate the Monday board query so this one calls the Get_1StPageGroup and Get_RemainingPagesGroup queries.

This will create a table with your board columns and another table with your groups for each record. Then in Power Query you can select Merge Queries (I chose to Merge as new) to merge the two tables into a single table. You can join the two tables using the ID column for the data. This will give you a nice clean table with group vales.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment