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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Netrelemo
Helper IV
Helper IV

How do I try/resolve in a function data source ?

I have a PowerQuery that has to iterate throught 1,000+ SharePoint sites, and pull some data from a specific list on each site. Now obviously each site, having it's own configuration means there's lots of room for mistakes.

There are four possible outcomes which I am trying to identify:

  1. The list is good, and I can retrieve the MAX of "last Modified date" 
  2. The list does not exist, so I need a label "No list exists"
  3. The list  has no records and is empty, so "Not used"
  4. The list cannot be access due to permission, so "Access Denied" 

So here's what my table of URLs looks like:

 

Col1Col2SiteURL
......https://.....sharepoint.com/sites/exmlex/ThisIsSite2/Forecast
......https://.....sharepoint.com/sites/exmlex2/ThisIsSite3/Forecast
......https://.....sharepoint.com/sites/exmlex/ThisIsSite67/Forecast
......https://.....sharepoint.com/sites/exmlex/ThisIsSite5/Forecast

 

Coincidentially it's some of the exmlex2 sites that are the culprits - but there is no predicting whch one will give problems. 

So each site has a list, with a specific name, and that is the list I want to check. 

The list name is "Forecast", obviously on each site each site, the list will have a different GUID, so it has to be done by name. 

What I am trying to achieve is this: 

 

Col1Col2SiteURLResult
......https://.....sharepoint.com/sites/exmlex/ThisIsSite2/ForecastLastModified
......https://.....sharepoint.com/sites/exmlex2/ThisIsSite3/ForecastNo list exists
......https://.....sharepoint.com/sites/exmlex/ThisIsSite67/ForecastAccess Denied
......https://.....sharepoint.com/sites/exmlex/ThisIsSite5/ForecastNot used
............

 

 

So... I need a table of URLs, and a custom function with some error handling. The process must complete, despite all obstacles. 

My biggest problem, is that I cannot make error handling work in a custom function, when the error is the datasource. 

 

 

 

let
    Source = ...,
    ....
    #"Added Custom" = Table.AddColumn(#"Source", "Forecast", each 
        try     
            interrogateList([siteURL])
        otherwise 
            "Something else unforseen" 
        ),
in
    #"Added Custom"

 

 

 

And here is the custom fuction interrogateList()

 

 

 

 

let
    Source = (URL as any) => 
    let
       Source2  = try 
                      SharePoint.Tables(URL, [ApiVersion = 15])
                      # if not empty, try get the last modified date
                  otherwise 
                       "Access Denied"
    in
        #"Source2"
in
    Source

 

 

The script runs fine but a "problem url" does not get trapped - it just bombs with "The credentials provided are invalid" - so this error handling is ineffective.

 

Another perspective: It's not an HTTP error - SharePoint is serving up the response just fine. 

It's an authentication issue. 

4 REPLIES 4
Anonymous
Not applicable

Hi @Netrelemo,

You can create a table with a list of these source SharePoint URLs, then you can add a custom column with try/otherwise structure and data connector to invoke and catch the result of these links.

Regards,

Xiaoxin Sheng

I know. That's exactly what I am doing now. But it doesn't work. 

Anonymous
Not applicable

Hi @Netrelemo,

Can you please share some more detail about your sceniaro? They should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

I've tried to reword the problem with more detail

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.