Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
Hello!
I have a SharePoint list that has files attached in the Attachments column.
I want to create a visual table in my Power BI that shows the attachment link for each item in this list, so that the user can click on the link and be redirected to the file if they want to download it. How can I get the attachment link from a SharePoint list and use it in Power BI?
Solved! Go to Solution.
Hi @nok , hello MattiaFratello, thank you for your prompt reply!
Create a new blank query and paste the following M code to meet your requirement:
let
SharePointSiteURL = "YourSharePointSiteUrl",
SharePointTenant="https://Yourtenantname.sharepoint.com",
API_URL = SharePointSiteURL & "/_api/web/lists/getbytitle('YourListName')/items?$expand=AttachmentFiles",
Source = Json.Document(Web.Contents(API_URL, [Headers=[#"Accept"="application/json;odata=nometadata"]])),
ListItems = Source[value],
ExpandedItems = Table.ExpandRecordColumn(Table.FromList(ListItems, Splitter.SplitByNothing()), "Column1", {"ID", "Title", "AttachmentFiles"}),
ExpandedAttachments = Table.ExpandListColumn(ExpandedItems, "AttachmentFiles"),
AttachmentUrls = Table.ExpandRecordColumn(ExpandedAttachments, "AttachmentFiles", {"ServerRelativeUrl"}),
FinalTable = Table.AddColumn(AttachmentUrls, "AttachmentLink", each SharePointTenant & [ServerRelativeUrl], type text),
ResultTable = Table.SelectColumns(FinalTable, {"ID", "Title", "AttachmentLink"})
in
ResultTable
Remember to cahnge the siteurl, tenantname, and listname to your specific values
After that, format the text in the column as a web URL:
My sample test for your reference:
Best regards,
Joyce
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @nok , hello MattiaFratello, thank you for your prompt reply!
Create a new blank query and paste the following M code to meet your requirement:
let
SharePointSiteURL = "YourSharePointSiteUrl",
SharePointTenant="https://Yourtenantname.sharepoint.com",
API_URL = SharePointSiteURL & "/_api/web/lists/getbytitle('YourListName')/items?$expand=AttachmentFiles",
Source = Json.Document(Web.Contents(API_URL, [Headers=[#"Accept"="application/json;odata=nometadata"]])),
ListItems = Source[value],
ExpandedItems = Table.ExpandRecordColumn(Table.FromList(ListItems, Splitter.SplitByNothing()), "Column1", {"ID", "Title", "AttachmentFiles"}),
ExpandedAttachments = Table.ExpandListColumn(ExpandedItems, "AttachmentFiles"),
AttachmentUrls = Table.ExpandRecordColumn(ExpandedAttachments, "AttachmentFiles", {"ServerRelativeUrl"}),
FinalTable = Table.AddColumn(AttachmentUrls, "AttachmentLink", each SharePointTenant & [ServerRelativeUrl], type text),
ResultTable = Table.SelectColumns(FinalTable, {"ID", "Title", "AttachmentLink"})
in
ResultTable
Remember to cahnge the siteurl, tenantname, and listname to your specific values
After that, format the text in the column as a web URL:
My sample test for your reference:
Best regards,
Joyce
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @nok, you can connect to your sharepoint list using
New Source -> Others -> SharePoint Online List
Use the truncated URL of your SP https://yoursharepointname.sharepoint.com/sites/xxx
Click then on Table under the column Items for the correct SP list you want to import
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 44 | |
| 43 | |
| 38 | |
| 19 | |
| 15 |
| User | Count |
|---|---|
| 67 | |
| 66 | |
| 31 | |
| 28 | |
| 24 |