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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Nick
Frequent Visitor

Getting SharePoint List items with full history version?

Hi,

 

We do have a SharePoint list to manage Fleet inventory of asset: mainly their attribution (who own it) and their status (active, lost, broken, etc.).

We did activated the SharePoint Version Control and I would like to use this information to run histroical report overtime around such assets status and ownership.

Right now, the only solution I found is to eitheir take a snapshot of the full list on a regular basis into another datasource.

Is there anyway to get such history/version data directly avoiding wruting such separate datasource?

 

Thansk in advance,

Nick

45 REPLIES 45

This is awesome! I just got a request if this was possible!

Anonymous
Not applicable

Awsome! You made my day. Thanks a lot. 🙂 

Anonymous
Not applicable

@JensG cool that you posted a function/query. Unfortunately, it does not work for me. Any ideal how I can fix that without too much effort. The error says Expression.Error: The access to the ressourc is prohibites (translated from my version: "Der Zugriff auf die Ressource ist untersagt."). I checked that I am properly logged in and check the list that there are no permission restrictions. At least I cannot see any. I am assuming that the account I am logged into PowerBI must also have access the SharePoint list or is there anything else I need to consider?

Are you sure that the links in your function are still valid?

http://schemas.microsoft.com/ado/2007/08/dataservices/metadata
http://schemas.microsoft.com/ado/2007/08/dataservices

 Appreciate, if someone has a clue what is wrong with it?

 

Thank you so much

Hi @Anonymous  

I had to add my SharePoint URL to this list of trusted sites in my Internet Options to overcome that error-message.

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Hi udobausc, 

 

sorry I don´t have seen this error on my end yet.

I´m logged in with my O365 Users in Power BI, same user who has access to the SP stuff.

Anyhow sometimes Power BI is promting to enter credentials where I can select differrent methods. But I always use the same user.

 

regarding the old links, it is when I expand some columns this is returned as field name and I have just kept it as it comes from the SP API 🙂


it might be worth to check if the underlying link is working in your browser when you replace the values in <>:

<VersionsRelevantSharePointLocation>/_api/web/Lists/getbytitle('<VersionsRelevantSharePointListName>')/items(<VersionsRelevantItemID>)/versions

 

have fun 

 

 

 

 

How do you expand this function to get the complete version history for all rows in a column?

Hi tdaskalakis,

 

here is an short example how to use the function:

1) Add an Query to your list where you want to see the version history:

 

	let
	    Source = SharePoint.Tables("https://<yourDomain>.sharepoint.com/sites/<YourSPSite>", [ApiVersion = 15]),
	    #"Filtered Rows" = Table.SelectRows(Source, each ([Title] = "SampleList")),
	    #"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows",{"Items", "Title"}),
	    #"Expanded Items" = Table.ExpandTableColumn(#"Removed Other Columns", "Items", {"Id"}, {"Items.Id"})
	in
	    #"Expanded Items"

2) Invoke the Custom Function "GetVersionHistoryFromSharePointList" (from post above)

powerbi-1.png

 

 

powerbi-2.png

3.) after the invoke your table will have the column version which contains an table which contains a table per version of the item.

powerbi-3.png

4) expand the Table.

powerbi-4.png

5) now you have all possible items in a list, now you can further expand specific columns as you need.
powerbi-6.png


Example code after those steps:

	let
	    Source = SharePoint.Tables("<Your SP Site Link>", [ApiVersion = 15]),
	    #"Filtered Rows" = Table.SelectRows(Source, each ([Title] = "SampleList")),
	    #"Removed Other Columns" = Table.SelectColumns(#"Filtered Rows",{"Items", "Title"}),
	    #"Expanded Items" = Table.ExpandTableColumn(#"Removed Other Columns", "Items", {"Id"}, {"Items.Id"}),
	    #"Invoked Custom Function" = Table.AddColumn(#"Expanded Items", "Versions", each GetVersionHistoryFromSharePointList([Title], "<Your SharePoint Site>", [Items.Id])),
	    #"Expanded Versions" = Table.ExpandTableColumn(#"Invoked Custom Function", "Versions", {"properties"}, {"Versions.properties"}),
	    #"Expanded Versions.properties" = Table.ExpandTableColumn(#"Expanded Versions", "Versions.properties", {"IsCurrentVersion", "VersionId", "VersionLabel", "Title", "ExampleText"}, {"Versions.properties.IsCurrentVersion", "Versions.properties.VersionId", "Versions.properties.VersionLabel", "Versions.properties.Title", "Versions.properties.ExampleText"})
	in
	    #"Expanded Versions.properties"



This is great by the way, but for me it errors out when publish to Power BI service do to a query being called inside another query.

Great post, thank you very much!

Anonymous
Not applicable

Awsome! You made my day. Thanks a lot. 🙂

Anonymous
Not applicable

This one worked for me:

https://sharepoint.stackexchange.com/questions/190021/exporting-item-list-version-history

Man Happy

 

Short explaination:

The "&IncludeVersions=TRUE" gives all changes form all versions (form all fields)

Make a Sharepoint List which only contains the columns you need. (or split it up in several views and repeat this trick)

 

Open the XML in Excel en there you can create a PivotTable and if you include the version field in SharePoint view.

You can see the version number in the Pivot Smiley Very Happy Just sort on this version number and you will see the latest and all previous versions.

There appears to be a 30 column limit on the &IncludeVersions=TRUE approach

There appears to be a 30 column limit on the &IncludeVersions=TRUE approach

llaumans
Frequent Visitor

Hi Nick,

 

did you ever figure out how to retrieve the history for items in a SharePoint list so you could run historical reports on your data? I would be very interested to learn how you managed to get this done!

 

Thanks in advance!

 

Kind Regards,

 

Lucas

 

Nick
Frequent Visitor

Hi Lucas,

 

The current workaround I'm currently using since I don't have access to SharePoint DB/Framework is via R script:

 

Here I'm taking snapshot of Group, Status, Id, and ExtractDate data into a local CSV file, everytime I'm refreshing the Data Source.

 

Not fancy but it does the job for now.

Hope that will help.

 

Nick

Anonymous
Not applicable

This one worked for me:

https://sharepoint.stackexchange.com/questions/190021/exporting-item-list-version-history

Man Happy

 

Short explaination:

The "&IncludeVersions=TRUE" gives all changes form all versions (form all fields)

Make a Sharepoint List which only contains the columns you need. (or split it up in several views and repeat this trick)

 

Open the XML in Excel en there you can create a PivotTable and if you include the version field in SharePoint view.

You can see the version number in the Pivot Smiley Very Happy Just sort on this version number and you will see the latest and all previous versions.

v-ljerr-msft
Microsoft Employee
Microsoft Employee

@Nick


Right now, the only solution I found is to eitheir take a snapshot of the full list on a regular basis into another datasource.

Is there anyway to get such history/version data directly avoiding wruting such separate datasource?


You can export version history of SharePoint List Items to Microsoft Excel first. Then export that Excel table to your SharePoint List. So that the version history and  other data will be in the same datasource.

export.PNG

 

sharepointlist.PNG

Regards


@v-ljerr-msft

Thanks but I can't execute PS scrript right now due to my company policies.

In addition I also wanted to avoid data multipliciation: maybe SharePoint list may not be good for what I'm looking for and I may ave to swicth to a real DB model.

Greg_Deckler
Super User
Super User

Well, you can get version history like so:

 

http://<server>/<site>/_layouts/versions.aspx?list={litsID}&ID=<itemID>

 

Here are some resources that might assist:

http://stackoverflow.com/questions/24423657/sharepoint-2013-get-splistitem-versions-via-rest

http://www.c-sharpcorner.com/UploadFile/anavijai/how-to-get-the-file-versions-in-sharepoint-2013-onl...

https://social.msdn.microsoft.com/Forums/en-US/79945c1d-1581-4441-bc13-14d119aa6a64/document-version...


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Is there any update for this solution, considering this was a post from 2016? 

These solutions work well in PBI Desktop but when publishing to the service I'm unable to refresh the dataset.

Hi, @s-roberts  ,

 

Try the solution suggested by Chris Webb here.

As I understand it, you need to hide away part of the API call's string from Power Query and append it during the run, so the code would look like this:

Web.Contents("<your-webpage>",[RelativePath = "<continuation of the API call>"])

I was able to pull in full version history and be able to set auto-refresh on the Service. 

 
Thanks 
Evan

Helpful resources

Announcements
July 2024 Power BI Update

Power BI Monthly Update - July 2024

Check out the July 2024 Power BI update to learn about new features.

July Newsletter

Fabric Community Update - July 2024

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