Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! 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?
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!