Skip to content

Instantly share code, notes, and snippets.

@Guichaguri
Last active May 3, 2024 17:56
Show Gist options
  • Star 27 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Guichaguri/83a6d8ab6ce3a695dc104bb4eff9d73d to your computer and use it in GitHub Desktop.
Save Guichaguri/83a6d8ab6ce3a695dc104bb4eff9d73d to your computer and use it in GitHub Desktop.
Power BI Monday.com Query - Power Query M
// Queries Monday.com items from a specific board. Limits to 500 items.
// Tested in API version 2024-01
// Created by Guilherme Chaguri
// Replace the API Key and Board ID for it to work
// In Power BI: "Get Data" -> "Blank Query" -> Right click the "Query" in the left panel and open the "Advanced Editor" -> Paste this code
let
Key = "YOUR MONDAY API KEY",
Board = "YOUR MONDAY BOARD ID NUMBER",
Source = Web.Contents(
"https://api.monday.com/v2",
[
Headers=[
#"Method"="POST",
#"Content-Type"="application/json",
#"Authorization"="Bearer " & Key,
#"API-Version"="2024-01"
],
Content=Text.ToBinary("{""query"": ""query { boards(ids: " & Board & ") { items_page(limit: 500) { items { name, updated_at, group { title }, columns: column_values { column { title }, text, ...on DependencyValue { display_value }, ...on MirrorValue { display_value }, ...on BoardRelationValue { display_value } } } } } }""}")
]
),
Data = Table.FromList(Json.Document(Source)[data][boards]{0}[items_page][items], Record.FieldValues, {"Title", "UpdatedAt", "Group", "Columns"}),
#"Monday" = Table.FromRecords(Table.TransformRows(Data, each
List.Accumulate([Columns], [
Title = [Title],
UpdateDate = [UpdatedAt],
Group = [Group][title]
], (state, current) => Record.AddField(
state, current[column][title],
if Record.HasFields(current, "display_value") then current[display_value] ?? current[text] else current[text])
)
))
in
#"Monday"
@avneeshp86
Copy link

Hello Guys ,
im using this code in power bi but data is nt coming because I have set board permission in monday.com so can u plz help me how to I get all data in power bi because I have show only view permission data so I want to get all data.

// Queries Monday.com items from a specific board
// Created by Guilherme Chaguri
// Replace the API Key and Board ID for it to work

let
Key = "YOUR MONDAY API KEY V2",
Board = "YOUR MONDAY BOARD ID NUMBER",
Source = Web.Contents(
"https://api.monday.com/v2",
[
Headers=[
#"Method"="POST",
#"Content-Type"="application/json",
#"Authorization"="Bearer " & Key
],
Content=Text.ToBinary("{""query"": ""query { boards(ids: " & Board & ") { items { name, updated_at, group { title }, columns: column_values { title, text } } } }""}")
]
),
Data = Table.FromList(Json.Document(Source)[data][boards]{0}[items], Record.FieldValues, {"Title", "UpdatedAt", "Group", "Columns"}),
#"Monday" = Table.FromRecords(Table.TransformRows(Data, each
List.Accumulate([Columns], [
Title = [Title],
UpdateDate = [UpdatedAt],
Group = [Group][title]
], (state, current) => Record.AddField(state, current[title], current[text]) )
))
in
#"Monday"

@Kaique-Yuto
Copy link

THANK YOU FOR THAT SIR 👍👍👍👍👍👍👍👍

@bugi666
Copy link

bugi666 commented Jan 2, 2024

@Guichaguri will the upcoming Monday API changes have any effect on this script?

Me too would like to know if the script will still work with API version 2023-10. thanks

@Guichaguri
Copy link
Author

will the upcoming Monday API changes have any effect on this script?

@KIRKBI-IT @bugi666 Yes, I have just updated it to the API version 2024-01.

@che0912crw
Copy link

Hi @Guichaguri I don't identify in the API documentation if is possible to get information from the .csv file attached in an update comment of one subitem to power query.

Would you mind advising about this?

@Kaique-Yuto
Copy link

Kaique-Yuto commented Jan 12, 2024

will the upcoming Monday API changes have any effect on this script?

@KIRKBI-IT @bugi666 Yes, I have just updated it to the API version 2024-01.

@Guichaguri I believe you have to use cursor pagination on the new API Version. Otherwise it won't return all of the data

@Guichaguri
Copy link
Author

@che0912crw it is possible, just too specific. You would have to add way more API queries in order to achieve this.

@Kaique-Yuto yes, as it used to only fetch a handful of items, it won't fetch more than 500 items now. In order to achieve pagination, you either have to use another solution or greatly improve the script. Contributions are welcome :)

@KIRKBI-IT
Copy link

will the upcoming Monday API changes have any effect on this script?

@KIRKBI-IT @bugi666 Yes, I have just updated it to the API version 2024-01.

Thanks a lot! I appreciate it

@Kaique-Yuto
Copy link

@che0912crw it is possible, just too specific. You would have to add way more API queries in order to achieve this.

@Kaique-Yuto yes, as it used to only fetch a handful of items, it won't fetch more than 500 items now. In order to achieve pagination, you either have to use another solution or greatly improve the script. Contributions are welcome :)

Howard Bouk has a solution within PBI here. Hope it help's you guys

@Guichaguri
Copy link
Author

Howard Bouk has a solution within PBI here. Hope it help's you guys

@Kaique-Yuto Awesome! thanks for sharing!
Unfortunately, that script is not dynamic, you still have to predict how many pages you may have in order to repeat the code for each one of them. I think building a solution that automatically loops for each and every page until there's nothing left is possible

@uupaulx
Copy link

uupaulx commented Jan 31, 2024

Howard Bouk has a solution within PBI here. Hope it help's you guys

@Kaique-Yuto Awesome! thanks for sharing! Unfortunately, that script is not dynamic, you still have to predict how many pages you may have in order to repeat the code for each one of them. I think building a solution that automatically loops for each and every page until there's nothing left is possible

How can you automatically loop for each every page?

@user24681092838
Copy link

There is no way to automatically do this, unless you know R or python as there maybe a solution using that. I have seen something in Power Bi for looping but am pretty sure its using parameters and stating the page numbers that you need.

This is what I have done, I create a parameter and just add 50 pages for it look up and that's it but if ever did it hit that amount the API would not even allow it and it code would not work. so I don't see any reason to have a loop because you would just hit barrier of the data you can bring into power bi from Monday.com.

@Wora2024
Copy link

Wora2024 commented Feb 5, 2024

I modify code to add Recursive Function and used it in my work.
I feel free to share my modified code with all of you for free.

Get Monday Data API-2024-01 v1.0.pbix

@andersonbezerrasantos
Copy link

worked perfectly <3

@jsisan7
Copy link

jsisan7 commented Feb 18, 2024

Hi, has anyone figured out how to extract more than 500 items?

@stevenromanous
Copy link

stevenromanous commented Feb 22, 2024

@Guichaguri- great M code.
How can I edit the code, to pre-exclude an unwanted column?
(the code does not run as an error keeps showing regading this unwanted column)

@cgl775
Copy link

cgl775 commented Feb 27, 2024

How can this code be updated to account for expiring cursors? I've been using this for about a month but now am getting the following error, and I can't figure out how to fix it: error_message=CursorExpiredError: The cursor provided for pagination has expired. Please refresh your query and obtain a new cursor to continue fetching items

@rhiannec
Copy link

rhiannec commented Mar 1, 2024

Hello @Guichaguri I'd like to know what the source of this error is? I tried this with a test board and it works but when I incorporated the actual board, I get this error.
pbi error

@Thehammer53
Copy link

@rhiannec It is because you do not have access to that board.

@user1010101010101
Copy link

Anyone having same issue with credentials? Suggestions on the settings?
image

@stevenromanous
Copy link

@user1010101010101 yes me too! Would love to know how to get around this.

@Thehammer53
Copy link

@stevenromanous @user1010101010101 Try using https://api/monday.com/v2 instead. It should show in the dropdown.

@stevenromanous
Copy link

@Thehammer53 nice works now, thanks a million!

@user1010101010101
Copy link

user1010101010101 commented Mar 12, 2024

@Thehammer53

Thanks, but I had te regenerate the API token! Thanks for your reply anyway!

@stevenromanous
Copy link

Does anyone else have the issue of some columns not getting pulling through? Apparently formula columns do not work with the API...

@Thehammer53
Copy link

@stevenromanous monday.com’s API documentation says that formula Columns are not supported with their API. Monday’s formulas suck anyways. Just create calculated columns

@stevenromanous
Copy link

@Thehammer53 but the formulated columns in this one Monday board I have connected to Power BI, is picking up data from other Monday.com boards. Do u foresee a workaround here?

@Thehammer53
Copy link

@stevenromanous mirroring the columns might work but you could just create multiple tables in your power BI and create relations between them and then use a calculated column

@stevenromanous
Copy link

The thing with creating multiple tables is Power BI is that, I would need to constantly go in there and create new tables for new Monday.com projects. Not sustainable

I will try mirroring columns to see if that works, thanks for your guidance!

@tay5689
Copy link

tay5689 commented May 3, 2024

This really works, but, how can I use the code to extract subitens?

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