Forum Discussion
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
46 Replies
- JensGAdvocate II
Hi
I like to share a function/query which will help to get the Version details via SharePoint API for a list item.
Function/Query: let Source = (VersionsRelevantSharePointListName as text, VersionsRelevantSharePointLocation as text, VersionsRelevantItemID as number) => let Source = Xml.Tables(Web.Contents(Text.Combine({ VersionsRelevantSharePointLocation, "/_api/web/Lists/getbytitle('", VersionsRelevantSharePointListName , "')/items(", Text.From(VersionsRelevantItemID), ")/versions"} ))), entry = Source{0}[entry], #"Removed Other Columns2" = Table.SelectColumns(entry,{"content"}), #"Expanded content" = Table.ExpandTableColumn(#"Removed Other Columns2", "content", {"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"}, {"content"}), #"Expanded content1" = Table.ExpandTableColumn(#"Expanded content", "content", {"properties"}, {"properties"}), #"Expanded properties" = Table.ExpandTableColumn(#"Expanded content1", "properties", {"http://schemas.microsoft.com/ado/2007/08/dataservices"}, {"properties"}) in #"Expanded properties" in Source3 parameters are required for the function:
VersionsRelevantSharePointLocation => https://<yourAddress>.sharepoint.com/sites/<yourSite>
VersionsRelevantSharePointListName => Your SharePoint List Name
VersionsRelevantItemID => SharePoint list item ID
when you invoke this Function to an SharePoint list you get the table with all related versions for that item.
This can be further expanded to get to the full set of columns from that list.Hope this helps.
Have Fun!
- AnonymousNot applicable
please share how do we apply schedule refresh on this dynamic data source,
- mzzwtrRegular Visitor
Hi Anonymous,
I suggest you to read these articles:
- Setting a scheduled refresh on a Dynamic Data Source in Power BI
- Web.Contents(), M Functions And Dataset Refresh Errors In Power BI
- Using The RelativePath And Query Options With Web.Contents() In Power Query And Power BI M Code
To set a scheduled refresh using dynamic data source, I've edit the function of JensG in this way:
let Source = (VersionsRelevantSharePointListName as text, VersionsRelevantSharePointLocation as text, VersionsRelevantItemID as number) => let Source = Xml.Tables(Web.Contents( "https://YourAddress.sharepoint.com/sites/", [RelativePath = VersionsRelevantSharePointLocation & "/_api/web/Lists/getbytitle('" & VersionsRelevantSharePointListName & "')/items(" & Text.From(VersionsRelevantItemID) & ")/versions"] )), entry = Source{0}[entry], #"Removed Other Columns2" = Table.SelectColumns(entry,{"content"}), #"Expanded content" = Table.ExpandTableColumn(#"Removed Other Columns2", "content", {"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"}, {"content"}), #"Expanded content1" = Table.ExpandTableColumn(#"Expanded content", "content", {"properties"}, {"properties"}), #"Expanded properties" = Table.ExpandTableColumn(#"Expanded content1", "properties", {"http://schemas.microsoft.com/ado/2007/08/dataservices"}, {"properties"}) in #"Expanded properties" in Source3 parameters are required for the function:
- VersionsRelevantSharePointLocation => The subdirectory of your SharePoint site (is what come after ...sites/)
- VersionsRelevantSharePointListName => Your SharePoint List Name
- VersionsRelevantItemID => SharePoint list item ID
Then, once you have published your report into Power BI service, I raccomend to read these articles:
- [Unable to combine data] accessing data sources that have privacy levels
- Information is needed in order to combine data
Hope this may help you.
Bye!
- bibinthomasFrequent Visitor
Hi JensG,
The query is to get the version history of a single List Item (ID). How do we get the version history of all the list items.
- tdaskalakisNew Member
How do you expand this function to get the complete version history for all rows in a column?
- JensGAdvocate II
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)
3.) after the invoke your table will have the column version which contains an table which contains a table per version of the item.
4) expand the Table.
5) now you have all possible items in a list, now you can further expand specific columns as you need.
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"
- Greg_DecklerCommunity Champion
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
- s-robertsHelper I
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.
- AnonymousNot applicable
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.
ThanksEvan
- NickFrequent Visitor
Thanks but it looks I can only extract one version of a specific item. However thanks for sharing URLs: a solution may be around.
- thakksHelper I
Guys did you had any luck extracting all version from the sharepoint list by any chances..
- v-ljerr-msftMicrosoft Employee
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.
Regards
- NickFrequent Visitor
v-ljerr-msftThanks 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.
- llaumansFrequent 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
- NickFrequent 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
- AnonymousNot applicable
This one worked for me:
https://sharepoint.stackexchange.com/questions/190021/exporting-item-list-version-history
:manhappy:
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 :smileyvery-happy: Just sort on this version number and you will see the latest and all previous versions.
- AnonymousNot applicable
This one worked for me:
https://sharepoint.stackexchange.com/questions/190021/exporting-item-list-version-history
:manhappy:
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 :smileyvery-happy: Just sort on this version number and you will see the latest and all previous versions.
- madkins420New Member
There appears to be a 30 column limit on the &IncludeVersions=TRUE approach
- madkins420New Member
There appears to be a 30 column limit on the &IncludeVersions=TRUE approach
- mohandarNew Member
how can we get full version history of all items? I am trying to create report based on the no of days an item stayed in a particular status, any help will be appreciated.
- MD1New Member
Hello all,
I am trying to run this query but I am getting below error. Do you know what can be the reason of it?
- jdr4mcseNew Member
Is there a way to limit the amount of version returned by adding a date range into the api code? If so, do you know what code to add to include a date range?
- AP20202020New Member
I keep getting the below error
DataSource.Error: Web.Contents failed to get contents from 'https://aemocloud.sharepoint.com/sites/EnterprisePortfolioOfficeHub/EnterprisePortfolioOfficeHub/_api/web/Lists/getbytitle('Enterprise%20Demand%20Register%20(Working%20Version)')/items(1)/versions' (404): Not Found
- AnonymousNot applicable
Did you ever get this resolved?