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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

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
May Power BI Update Carousel

Power BI Monthly Update - May 2026

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

Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.