如何在Power Query中引用单元格的值 [英] How can I reference a cell's value in a Power Query

查看:3900
本文介绍了如何在Power Query中引用单元格的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个PowerQuery查询,我想在Excel文件中提供单元格的值。在这种特殊情况下,源文件名的完整路径。



有没有什么方法可以让它进入PowerQuery?

解决方案

这可以使用PowerQuery中的命名范围和自定义函数来实现:


  1. 命名您需要引用的单元格(在公式栏左侧的文件中输入名称) - 例如 SourceFile

  2. 插入一个新的空白PowerQuery查询(PowerQuery功能区 - >其他来源)

  3. 在PowerQuery编辑器中,转到查看 - >高级编辑器并粘贴以下代码;



 
rangeName)=>
Excel.CurrentWorkbook(){[Name = rangeName]} [Content] {0} [Column1]




  1. 将查询命名为 GetValue (右侧查询设置窗格中的Name属性)

现在,您可以使用 GetValue(cellName)访问您查询中的任何命名单元格

 
= Excel.Workbook(File.Contents(GetValue(SourceFile)))


I'm having multiple PowerQuery queries that I would like to feed the value of a cell in my Excel file. In this particular case, the full path to the sourcefile name.

Is there any way I can get this into PowerQuery?

解决方案

This can be achieved using a named range and a custom function in PowerQuery:

  1. Name the cell you need to refer (type in a name into the file left of the formula bar) - e.g. SourceFile
  2. Insert a new blank PowerQuery query (PowerQuery ribbon -> From other sources)
  3. In the PowerQuery editor, go to View -> Advanced Editor and paste the following code;

(rangeName) => 
    Excel.CurrentWorkbook(){[Name=rangeName]}[Content]{0}[Column1]

  1. Name the query to GetValue (Name property in the Query settings pane on the right)

Now you can access the any named cell in you queries, using GetValue(cellName) - e.g.

= Excel.Workbook(File.Contents(GetValue("SourceFile")))

这篇关于如何在Power Query中引用单元格的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆