Get certified for free when you join Fabric Data Days 2026 and dive into Fabric, Power BI, SQL, AI, and other essential data skills.
Join nowJuly 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more
Following numerous tutorials online, I have successfully configured a query in PowerBi to connect to Microsoft Graph and pull down a list of SharePoint Online Sites (and subsites). It uses a Azure app to provide the relevant permissions to get the data, with a shared seceret for authentication.
Here's the advanced query:
let
resource="https://graph.microsoft.com",
tokenResponse = Json.Document(Web.Contents("https://login.windows.net/",
[
RelativePath = #"Tenant ID" & "/oauth2/token",
Content = Text.ToBinary(Uri.BuildQueryString(
[
client_id = #"Azure Application ID",
resource = resource,
grant_type = "client_credentials",
client_secret = #"Azure Application Client Secret"
]
)),
Headers = [Accept = "application/json"], ManualStatusHandling = {400}
])),
access_token = tokenResponse[access_token],
Source = OData.Feed("https://graph.microsoft.com/beta/sites", [ Authorization = "Bearer " & access_token ], [ ExcludedFromCacheKey = {"Authorization"}, ODataVersion = 4, Implementation = "2.0" ]),
#"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type)
in
#"Added Index"Next I want to reduce the amount of data being imported, to speed things up. No point importing all of it and then filtering it, its going to be slow. (Something like 70% of the sites are going to be personal OneDrive sites)
The most obvious filter to start with is ignoring OneDrive sites by checking 'isPersonalSite' = FALSE. No matter syntax I try, it does not work.
Alternatively, looking in the 'id' for only <domainname>.sharepoint.com. ignoring all those that are <domainname>-my.sharepoint.com.
Any suggestions on how to get one of these working with Sites? (Ideally the 'isPersonalSite' one)
Thanks in advanced for ideas and suggestions 🙂
Solved! Go to Solution.
Hi @Blue407
After a bit of Googling and tinkering on my own tenant, the below query seems to work.
The changes I made were:
let
resource = "https://graph.microsoft.com",
tokenResponse = Json.Document(
Web.Contents(
"https://login.windows.net/",
[
RelativePath = #"Tenant ID" & "/oauth2/token",
Content = Text.ToBinary(
Uri.BuildQueryString(
[
client_id = #"Azure Application ID",
resource = resource,
grant_type = "client_credentials",
client_secret = #"Azure Application Client Secret"
]
)
),
Headers = [Accept = "application/json"],
ManualStatusHandling = {400}
]
)
),
access_token = tokenResponse[access_token],
Source = OData.Feed(
"https://graph.microsoft.com/beta/sites/getAllSites",
[Authorization = "Bearer " & access_token],
[
ExcludedFromCacheKey = {"Authorization"},
ODataVersion = 4,
Implementation = "2.0",
Query = [filter = "isPersonalSite eq false"]
]
),
#"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type)
in
#"Added Index"
Notes:
Does this work for you?
Hi @Blue407
After a bit of Googling and tinkering on my own tenant, the below query seems to work.
The changes I made were:
let
resource = "https://graph.microsoft.com",
tokenResponse = Json.Document(
Web.Contents(
"https://login.windows.net/",
[
RelativePath = #"Tenant ID" & "/oauth2/token",
Content = Text.ToBinary(
Uri.BuildQueryString(
[
client_id = #"Azure Application ID",
resource = resource,
grant_type = "client_credentials",
client_secret = #"Azure Application Client Secret"
]
)
),
Headers = [Accept = "application/json"],
ManualStatusHandling = {400}
]
)
),
access_token = tokenResponse[access_token],
Source = OData.Feed(
"https://graph.microsoft.com/beta/sites/getAllSites",
[Authorization = "Bearer " & access_token],
[
ExcludedFromCacheKey = {"Authorization"},
ODataVersion = 4,
Implementation = "2.0",
Query = [filter = "isPersonalSite eq false"]
]
),
#"Added Index" = Table.AddIndexColumn(Source, "Index", 0, 1, Int64.Type)
in
#"Added Index"
Notes:
Does this work for you?
Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.
Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.
| User | Count |
|---|---|
| 8 | |
| 5 | |
| 5 | |
| 4 | |
| 4 |