cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Netrelemo
Helper III
Helper III

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
v-shex-msft
Community Support
Community Support

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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

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

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

I've tried to reword the problem with more detail

Helpful resources

Announcements
Carousel_PBI_Wave1

2023 Release Wave 1 Plans

Power BI release plans for 2023 release wave 1 describes all new features releasing from April 2023 through September 2023.

Power BI Summit Carousel 2

Global Power BI Training

Make sure you register today for the Power BI Summit 2023. Don't miss all of the great sessions and speakers!

Thank you 2022 Review

2022 Monthly Feature Releases

We had a great 2022 with a ton of feature releases to help you drive a data culture.