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
avi081265
Helper III
Helper III

How to combine SharePoint List from multiple SharePoint sites

Hello 

 

I want to combine SharePoint List from different SharePoint sites. All the list having same kind of structure. My Idea that I will create one SharePoint LIst which we will have four columns i.e. Tenant Name,SIte Name,List Name and Site code. Then I want to read the data from this list and append or merge all the list which are exist in above list.

 

Please let me know how can I achieve this. If any article or Video please let me know.

 

Regards

Avian

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I cannot share the pbix sample but I can provide the explanation of the code:

The code is designed to fetch data from multiple SharePoint lists based on the URLs and list names provided in an Excel file.

The first part of the code reads an Excel file. This Excel file contains a list of SharePoint site URLs and corresponding list names. The Excel.Workbook function is used to load the Excel file, and the Table.RenameColumns function is used to rename the columns to "Site URL" and "List Name".

Next, a custom function named FetchList is defined. This function takes a SharePoint site URL as an argument and returns a table of all lists in the SharePoint site. The SharePoint.Tables function is used to fetch the lists from the SharePoint site.

Finally, a new column named "Custom" is added to the table. For each row in the table, the FetchList function is called with the site URL from that row. The result is a table with an additional column that contains the SharePoint lists for each site URL.

This code is a common pattern in Power Query M language for fetching and combining data from multiple sources based on a list of parameters.

View solution in original post

27 REPLIES 27
Anonymous
Not applicable

Sure here is my code:

 

let
    // Get the list of SharePoint sites and corresponding list names
    ParameterTable = Excel.Workbook(File.Contents("C:\myparameters.xlsx"), null, true),
    Sheet1_Sheet = ParameterTable{[Item="Sheet1",Kind="Sheet"]}[Data],
    #"Renamed Columns" = Table.RenameColumns(Sheet1_Sheet,{{"Column1", "Site URL"}}),
    #"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"Site URL", type text}, {"Column2", type text}}),
    #"Renamed Columns1" = Table.RenameColumns(#"Changed Type",{{"Column2", "List Name"}}),

    // Add a custom function to fetch data from the corresponding SharePoint list for each SharePoint site
    FetchList = (site as text) => 
        let
            Source = SharePoint.Tables(site, [ApiVersion = 15])
        in
            Source,

    // Add a new column "Custom" to call the custom function for each row
    AppendLists = Table.AddColumn(#"Renamed Columns1", "Custom", each FetchList([Site URL]))
in
    AppendLists

and in the first comumn named "Site URL" of my parameter table, I have urls that look like this:
https://my.sharepoint.com/sites/AO1_FND
https://my.sharepoint.com/sites/AO1_FFF
and so on.

Unfortunately, refreshing dynamic data sources is not possible in Power BI Service and if I use the function Web.Contents I face the authentication error even though I am the admin of the SharePoint and I can import the data using the code above. I am so lost and so puzzled that such an issue does not have a straighforward solution. Maybe uploading the data to Dataverse could solve this issue?

Hello Samper,

 

Following function is not clear to me, you have column name "site url" which is fetching from excel. How this site url is relating with folllowing function, can you please explain anf if posible please share the sample power BI for more clarity.

 

// Add a custom function to fetch data from the corresponding SharePoint list for each SharePoint site FetchList = (site as text) =>

let Source = SharePoint.Tables(site, [ApiVersion = 15])

in Source

 

Regards

Avian

 

Anonymous
Not applicable

I cannot share the pbix sample but I can provide the explanation of the code:

The code is designed to fetch data from multiple SharePoint lists based on the URLs and list names provided in an Excel file.

The first part of the code reads an Excel file. This Excel file contains a list of SharePoint site URLs and corresponding list names. The Excel.Workbook function is used to load the Excel file, and the Table.RenameColumns function is used to rename the columns to "Site URL" and "List Name".

Next, a custom function named FetchList is defined. This function takes a SharePoint site URL as an argument and returns a table of all lists in the SharePoint site. The SharePoint.Tables function is used to fetch the lists from the SharePoint site.

Finally, a new column named "Custom" is added to the table. For each row in the table, the FetchList function is called with the site URL from that row. The result is a table with an additional column that contains the SharePoint lists for each site URL.

This code is a common pattern in Power Query M language for fetching and combining data from multiple sources based on a list of parameters.

Thanks for Explanation, I wil try and let you know if I have any more queries.

Hello 

Thanks for the solution. I am newbie in Power BI, how to use above mentioned in Power BI?

Happy to help. Kudos will be more appropriated. 

 

Go to power query. Open advanced editor. And try copy paste the code. But you need to adjust the code value with your own value. 

 

Did I help? If yes, hit 👍

 

If this is helpfull, accept this post as a solution. 

 


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Helpful resources

Announcements
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.

Top Solution Authors