Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Blue407
Frequent Visitor

Filtering query for PowerBi Odata from Graph, for SharePoint Online Sites

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 🙂

 

 

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

Hi @Blue407 

After a bit of Googling and tinkering on my own tenant, the below query seems to work.

The changes I made were:

  1. Change the serviceUri (1st argument of OData.Feed) to
    "https://graph.microsoft.com/beta/sites/getAllSites"
  2. Add a Query record within the options record (3rd argument of Odata.Feed) equal to
    Query = [filter = "isPersonalSite eq false"]
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:

  • Documentation for sites/getAllSites
  • You may receive a property @odata.nextLink in the response, so may have update the query to iterate to update to iterate through pages.

Does this work for you?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

1 REPLY 1
OwenAuger
Super User
Super User

Hi @Blue407 

After a bit of Googling and tinkering on my own tenant, the below query seems to work.

The changes I made were:

  1. Change the serviceUri (1st argument of OData.Feed) to
    "https://graph.microsoft.com/beta/sites/getAllSites"
  2. Add a Query record within the options record (3rd argument of Odata.Feed) equal to
    Query = [filter = "isPersonalSite eq false"]
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:

  • Documentation for sites/getAllSites
  • You may receive a property @odata.nextLink in the response, so may have update the query to iterate to update to iterate through pages.

Does this work for you?


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.