简体   繁体   English

Power M查询语法以获取Excel中命名单元格的值

[英]Power M query syntax to get the value for a named cell in Excel

I am still learning about Power Query and Power M and I'm trying to get the value of a specific "named" cell in Excel and use this in Power M. It is just a single cell and 我仍在学习Power Query和Power M,我试图在Excel中获取特定“命名”单元格的值,并在Power M中使用它。它只是一个单元格,

一周

=Record.Field(Excel.CurrentWorkbook(){[Name="weekone"]}[Content]{0},Excel.CurrentWorkbook(){[Name="weekone"]}[Content]{0})

Maybe I am not understanding the syntax of how to reach information in a particular field correctly, or I am getting mixed up on how to use the Record.Field() function. 也许我不了解如何正确到达特定字段中的信息的语法,或者我对如何使用Record.Field()函数感到困惑。

Any help or guidance that can be provided would be greatly appreciated! 可以提供的任何帮助或指导将不胜感激! Thanks! 谢谢!

Record.Field gives the value of a field in a record. Record.Field给出记录中字段的值。 It takes the record as the first argument and the name of the field as the second argument. 它以记录作为第一个参数,并以字段名称作为第二个参数。

In a step by step approach it will be clearer: 在逐步方法中,将更加清楚:

let
    Source = Excel.CurrentWorkbook(){[Name="weekone"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type date}}),
    FirstRecord = #"Changed Type"{0},
    RecordValue = Record.Field(FirstRecord,"Column1")
in
    RecordValue

Or, in 1 line: 或者,在1行中:

= DateTime.Date(Record.Field(Excel.CurrentWorkbook(){[Name="weekone"]}[Content]{0},"Column1"))

This would be an alternative: 这是一种替代方法:

= DateTime.Date(Excel.CurrentWorkbook(){[Name="weekone"]}[Content]{0}[Column1])

My preference would be: 我的偏好是:

= DateTime.Date(Table.FirstValue(Excel.CurrentWorkbook(){[Name="weekone"]}[Content]))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM