Forum Discussion
Getting SharePoint List items with full history version?
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!
please share how do we apply schedule refresh on this dynamic data source,
- mzzwtr4 years agoRegular 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!
- Anonymous4 years agoNot applicable
THANKS A LOT, ❤️ YOU SAVED MY DAY 🙂 YOUR ABOVE CODE WORS FINE
- harsh_bi_dev3 years agoFrequent Visitor
Hello mzzwtr ,
Thanks for this answer. I'm facing an issue with the solution you provided in Power BI Service as below.Please know that it is working fine in the Power BI Desktop but not on Power BI Service.
Please help me out with this.
- mzzwtr3 years agoRegular Visitor
Hi harsh_bi_dev ,
could you show me how you connected the SharePoint Online List data source to your Power BI dashboard?
I followed this guide:
https://docs.microsoft.com/en-us/power-bi/connect-data/desktop-sharepoint-online-list
Another question, could you show me what steps you took to publish your Power BI dashboard into your Power BI Service workspace?
I followed this guide:
https://docs.microsoft.com/en-us/power-bi/create-reports/desktop-upload-desktop-files
Hope this may help you.Bye!
- GabrielMacedo3 years agoNew Member
It worked fine here, thank you very much.