如何为来自SharePoint的文件创建动态文件路径,以查询power查询?
上下文:我最近接受了一份新工作,并且正在培训我的替代品。我已经为该公司建立了许多报告,其中大多数已保存给我的OneDrive。我一直在将这些文件移至SharePoint网站上,学员可以使用,这需要我在报告中修复电源查询,以便当她刷新工作簿中的链接时,它可以从同一工作簿中的另一个工作簿中吸取数据SharePoint。
问题:我正在使用SharePoint中的“添加快捷方式”功能,因此我可以从文件资源管理器访问文件,因此,当我选择文件时,它会从我的用户名中构建路径,以防止她刷新她由于文件路径是无法访问的,因此该工作簿。
我采取的步骤:我读了这篇文章 https://excel.tv/how-to-to-to-create-a-relative-file-path-path-in-power-query/ ,我认为这使我朝着正确的方向朝着正确的方向从硬盘驱动器上的所有文件的角度来看,而不是来自SharePoint网站。当我在SharePoint上共享该公式中输入此公式时:
=LEFT(CELL(“filename”,$A$1),FIND(“[“,CELL(“filename”,$A$1),1)-1)
它没有在其中返回用户名返回filepath,而是返回https链接(例如 https://sharepoint.com/teams/sharedhub ),哪个)然后,Power查询会呼叫错误,因为它不是有效的绝对路径。另外,要参考,这是高级编辑器的代码块。
let
Filepath = Excel.CurrentWorkbook(){[Name="Filepath"]}[Content]{0}[Column1],
Source = Excel.Workbook(File.Contents(Filepath & "The SharePoint File.xlsx"), null, true),
tbl_nexidia_Table = Source{[Item="tbl",Kind="Table"]}[Data]
in
tbl_Table
我还尝试使用获取数据构建新查询 - >从文件 - >从SharePoint文件夹中,但这似乎可以从SharePoint中提取所有文件夹名称,我还没有弄清楚如何钻到特定的工作簿以从特定表中获取数据。
非常感谢您的帮助!
Context: I recently accepted a new job and I'm training my replacement. I've built a lot of reports for the company and a majority of them have been saved to my OneDrive. I've been moving these files over to a SharePoint site the trainee can use which has required me to fix the power queries in my reports so that when she refreshes the links in the workbook that it pulls in data from another workbook present on the same sharepoint.
Problem: I'm using the "Add shortcut to OneDrive" feature from SharePoint so I can access the files from my file explorer, so when I go to select the file it builds a path from my username, preventing her from being able to refresh the workbook since the file path is inaccessable.
Steps I've Taken: I read this article https://excel.tv/how-to-create-a-relative-file-path-in-power-query/ and I think this is taking me in the right direction except its from the perspective of all the files being located on your hard drive and not from a SharePoint site. When I enter in this formula into the file I'm sharing on the SharePoint:
=LEFT(CELL(“filename”,$A$1),FIND(“[“,CELL(“filename”,$A$1),1)-1)
Instead of returning the filepath with my username in it, it returns a https link (eg. https://sharepoint.com/teams/SharedHub), which power query then calls an error on since it's not a valid absolute path. Also, for reference, here's the code block from the advanced editor.
let
Filepath = Excel.CurrentWorkbook(){[Name="Filepath"]}[Content]{0}[Column1],
Source = Excel.Workbook(File.Contents(Filepath & "The SharePoint File.xlsx"), null, true),
tbl_nexidia_Table = Source{[Item="tbl",Kind="Table"]}[Data]
in
tbl_Table
I also tried building a new query using Get data --> From File --> From SharePoint Folder but that seems to pull in all the folder names from the SharePoint and I haven't figured out how I drill down to a specific workbook to get data from a specific table.
Would very much appreciate some help on this!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一下。将Excel Workbook放入SharePoint之后,请从SharePoint内部打开工作簿,然后选择编辑下拉列表, 在桌面应用程序中打开:
然后,在工作簿中,单击 file > info > 复制路径。 (这将为您提供电源查询所需的路径才能直接检索工作簿。如果您尝试使用SharePoint的功能复制路径的路径,这与您所获得的路径不同。)
粘贴该路径以安全地使用。然后关闭您的工作簿并打开电源查询。
在电源查询中,创建两个新参数:
单击 home > 管理参数的底部按钮> 新参数:
将名称从 parameter1 更改为路径并将类型更改为 text ,然后将您复制的工作簿复制的路径粘贴到当前值 box 。然后,从刚粘贴的路径中删除了最后一个前向斜线(/)之后的所有文本。确保您做< / strong>将最后 /包含在路径中。您将在单独的参数中放置以下内容的文件名,并且不需要?web = 1 < / em>。
不要单击确定。,请单击 new ,在管理参数窗口的顶部。这将设置您创建文件名参数。
将名称从 parameter1 更改为 fileName ,然后将 type 更改为 text ,然后粘贴您复制的文件名工作簿进入当前值框。同样,您不需要原始路径中的?web = 1 。
单击确定。
现在,您可以在源行中使用参数,路径和文件名。这是这样做的方法:
这将为您提供这样的表:
------------------------------------------------------------------------ -
对于Mirza的后续操作,关于从SharePoint文件夹中提取文件,请尝试以下操作:
连接。
您的 root 在SharePoint中使用文件夹,然后单击“确定”。
想打开。 (使用顶端的下拉箭头。)
文件可以存储在多个文件夹中,您需要确保
您正在通过与正确的文件匹配正确的文件
文件夹,这为此设定了阶段。)
您应该以这样的代码结束(yourdomain.sharepoint.com/your/root/folder/url将是您的 root root 在SharePoint中的文件夹):
您应该看到类似的东西此:
在内容列中单击二进制文件。
------------------------------------------------------------------------ -
对于Mirza的第二次随访,关于从SharePoint文件夹中摘取多个文件而不是仅一个文件,请尝试以下操作:
连接。
在SharePoint中使用文件的root文件夹,然后单击“确定”。你可能有
输入您的凭据。如果是这样,请这样做。
粘贴您刚刚从文件夹路径列复制到的路径
路径参数的当前值:
单击“家”,然后单击“管理参数”,然后,如果您尚未创建路径参数,请单击新(否则单击路径参数以选择它):
单击“ .sstatic.net/vggHt.png" rel="nofollow noreferrer">
确保您的路径参数如下:
然后,在过滤行的公式框中,更改
路径(包括引号)到路径。也就是说,更改此信息:
= table.selectrows(源,每个([folder path] =“ https://yourdomain.sharepoint.com/sites/testteam/shared documents /shared documents/enter/general/”))
to ...
= table.selectrows(源,每个(([folder path] = path)))
您应该能够用任何其他有效根文件夹中的文件夹路径。
由于这些源文件位于SharePoint内,因此SharePoint的访问控件占上风。因此,要使用户能够访问实际的源文件,这是刷新需要做的,需要刷新的用户将需要适当的SharePoint访问权限的源文件以访问它们。但是,我可以肯定的是,一旦完成了刷新,任何可以访问您的文件的用户(无论是在Excel还是Power BI文件中)都应该能够看到其结果,而没有他们的结果需要对基础源文件的SharePoint访问权限。我的理解是,只有那些实际访问源文件(例如刷新)的人才需要访问这些文件的人。无论如何,这是我的经验。
Try this. After you have placed your excel workbook into SharePoint, open the workbook from within SharePoint and then select the Editing dropdown and Open in Desktop App:
Then, in the workbook, click File > Info > Copy Path. (This will get you the path you need for power query to directly retrieve the workbook. It is different than what you would have gotten if you tried to copy the path using SharePoint's features for copying the path.)
Paste that path somewhere safe for reuse. Then close your workbook and open Power Query.
In Power Query, create two new parameters:
Click Home > the bottom part of the Manage Parameters button > New Parameters:
Change the name from Parameter1 to path and change the Type to Text, then paste the path you copied for your workbook into the Current Value box. Then, from the path you just pasted, delete all the text that follows the last forward slash (/). Make sure you do include that last / in the path. You'll put the file name that follows the / in a separate parameter and won't need the ?web=1.
Don't click OK. Instead, click New, at the top of the Manage Parameters window. This will set you up to create the filename parameter.
Change the name from Parameter1 to filename and change the Type to Text, then paste the filename you copied for your workbook into the Current Value box. Again, you won't need the ?web=1 from the original path.
Click OK.
Now you can use the parameters, path and filename in your source line. And here's how to do that:
This will give you a table like this:
-------------------------------------------------
For Mirza's follow-up, regarding pulling the files from the SharePoint folder, try this instead:
Connect.
your root folder for your files in SharePoint and click OK.
want to open. (Use the dropdown arrow at the top-right.)
files can be stored in multiple folders and you'll want to be sure
you are selecting the right file by matching it with its correct
folder, and this sets the stage for that.)
You should wind up with code like this (yourdomain.sharepoint.com/your/root/folder/URL would be your URL to your root folder for your documents in sharepoint instead):
You should see something like this:
Click Binary, in the Content column.
-------------------------------------------------
For Mirza's second follow-up, regarding pulling multiple files from the SharePoint folder instead of just one file, try this instead:
Connect.
root folder for your files in SharePoint and click OK. You may have
to enter your credentials. If so, do that.
To paste the path you just copied from the Folder Path column to the
path parameter's current value:
Click Home, then click on Manage Parameters, then if you haven't already created the path parameter, click new (otherwise click on the path parameter to select it):
Make sure your path parameter is set up like this:
Then, in the formula box for the Filtered Rows, change the name of
the path (including the quotes) to path. That is, change this:
= Table.SelectRows(Source, each ([Folder Path] = "https://yourdomain.sharepoint.com/sites/TestTeam/Shared Documents/General/"))
to...
= Table.SelectRows(Source, each (([Folder Path] = path)))
You should be able to replace the current value of the path parameter with any other valid folder path within your root folder.
Since these source files reside within SharePoint, SharePoint's access controls prevail. So, for a user to be able to access the actual source files, which is what a refresh needs to do, the users who need to refresh will need appropriate SharePoint access rights to the source files in order to access them. However, I'm fairly certain that once the refresh has been done, any users who have access to your file that is built from this query's results (be it in an excel or Power BI file) should be able to see its results without them needing SharePoint access rights to the underlying source files. My understanding is that only those people who actually access to the source files, like for refresh, require the SharePoint access to those files. This has been my experience anyway.
有一个用于电源查询本机的文件的SharePoint连接器,不会使用您的用户名。
https://learn.microsoft.com/en-en-poper-us/power-us-poper-us-us-us-us-us-us-us-us-us-us-us-us-us-us-us-us-us-us-us-us-us-us-us-us-us-poper-us-us-us-查询/连接器/sharepointFolder
旁注,您不能使用
cell
函数,There is a SharePoint connector for files native to Power Query, that will not use your username.
https://learn.microsoft.com/en-us/power-query/connectors/sharepointfolder
Side note, you cannot use
CELL
function because