电源查询:选择查询要应用于的文件的简便方法?

发布于 2025-02-07 16:45:02 字数 480 浏览 2 评论 0原文

在我们的实验室中,我们有一个系统,许多人使用并生产出结果奇怪的TXT文件。我创建了一个清除文件的电源查询,我想与他人分享(不是很精通计算机),以便他们可以将其应用于将生成的文件。

我该怎么做才能使其他用户尽可能容易地选择他们希望将查询应用于的文件?示例:是否有一种简单的方法来创建按钮打开请求文件位置的对话框?现在,我必须编辑查询源以选择数据,此方法很笨拙,我的某些同事会感到困惑。

let
Source = Table.FromColumns({Lines.FromBinary(File.Contents("X:\foo\foo.txt"), null, null, 1252)}),
#"Removed Top Rows2" = Table.Skip(Source,32),
#"Removed Bottom Rows" = Table.RemoveLastN(#"Removed Top Rows2",16),
#"Other Steps" = ...

谢谢!

In our lab we have a system that many people uses and produces a oddly shaped txt file with the results. I created a power query that cleans the file and I would like to share this with others (not very computer savvy) so they can apply it to the files they will generate.

What can I do to make it as easy as possible for other users to select the file they want the query to be applied to? Example: is there an easy way to create button that opens a dialog requesting the file location? Right now I have to edit the query source to select the data, this approach is clunky and will be confusing for some of my colleagues.

let
Source = Table.FromColumns({Lines.FromBinary(File.Contents("X:\foo\foo.txt"), null, null, 1252)}),
#"Removed Top Rows2" = Table.Skip(Source,32),
#"Removed Bottom Rows" = Table.RemoveLastN(#"Removed Top Rows2",16),
#"Other Steps" = ...

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

萌辣 2025-02-14 16:45:02

您可以直接从范围名称单元格中直接获取filepath,而无需通过函数

let
NameValue= Excel.CurrentWorkbook(){[Name="rangenamehere"]}[Content]{0}[Column1],
Source = Table.FromColumns({Lines.FromBinary(File.Contents(NameValue), null, null, 1252)}),

或想要文件提示的vba路由

1创建范围名称,here aaa

2使用vba要使用文件提示填充它

Sub prompt()
Dim FName As Variant
FName = Application.GetSaveAsFilename("", "Data file (*.xl*),*.xl*", 1)
If FName = False Then
MsgBox "False"
Exit Sub
End If
Range("aaa").Value = FName
End Sub

设置4个钉的命名范围,

let
NameValue= Excel.CurrentWorkbook(){[Name="aaa"]}[Content]{0}[Column1],
Source = Table.FromColumns({Lines.FromBinary(File.Contents(NameValue), null, null, 1252)}),

3请参考您在VBA末尾在代码上

ActiveWorkbook.RefreshAll

以刷新所有查询或特定查询或

ActiveWorkbook.Queries("QueryNameHere").Refresh

You can directly grab a filepath from a range name cell without a function by

let
NameValue= Excel.CurrentWorkbook(){[Name="rangenamehere"]}[Content]{0}[Column1],
Source = Table.FromColumns({Lines.FromBinary(File.Contents(NameValue), null, null, 1252)}),

Or if you wanted the VBA route for file prompt

1 Create a range name, here aaa

2 Use VBA to populate it using a file prompt

Sub prompt()
Dim FName As Variant
FName = Application.GetSaveAsFilename("", "Data file (*.xl*),*.xl*", 1)
If FName = False Then
MsgBox "False"
Exit Sub
End If
Range("aaa").Value = FName
End Sub

3 Refer to the named range in powerquery you set up

let
NameValue= Excel.CurrentWorkbook(){[Name="aaa"]}[Content]{0}[Column1],
Source = Table.FromColumns({Lines.FromBinary(File.Contents(NameValue), null, null, 1252)}),

4 Tack on code at end of VBA to refresh all queries or specific query

ActiveWorkbook.RefreshAll

or

ActiveWorkbook.Queries("QueryNameHere").Refresh
夜空下最亮的亮点 2025-02-14 16:45:02

您可以将fngetParameter变成一个单线:

= ( getValue as text ) => Excel.CurrentWorkbook(){[Name=”Parameters”]}[Content]{[Parameter=getValue]}?[Value]?

You can make the fnGetParameter into a one-liner:

= ( getValue as text ) => Excel.CurrentWorkbook(){[Name=”Parameters”]}[Content]{[Parameter=getValue]}?[Value]?
薯片软お妹 2025-02-14 16:45:02

我发现 /a>从2014年起运行良好。您在查询(fngetParameter)上编写一个函数,该功能从表中读取文件位置,然后将其馈送到处理数据的查询。

用户需要做的就是在表格上写文件位置以及名称和刷新。

我将第一个更改为PowerQuery代码上的行,看起来像这样:

    Fileloc = fnGetParameter("File Path"),
    Source = Table.FromColumns({Lines.FromBinary(File.Contents(Fileloc), null, null, 1252)}),

有什么建议以使其变得更好?

I found this post from 2014 that works pretty well. You write a function on Query (fnGetParameter) that reads the file location from a table and then you feed it to the query that processes the data.

All the user needs to do is write the file location on the table and name and refresh.

I changed the first to lines on my PowerQuery code to look like this:

    Fileloc = fnGetParameter("File Path"),
    Source = Table.FromColumns({Lines.FromBinary(File.Contents(Fileloc), null, null, 1252)}),

Any suggestions to make it even better?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文