[英]Power BI M Language List.Select How to filter by Date
When I use this: List.Select({[Date1], [Date2], [Date3]}, each _ < [Date4]) it returns error.当我使用这个: List.Select({[Date1], [Date2], [Date3]}, each _ < [Date4]) 它返回错误。 But when I use this code: List.Select({"2020-01-01", "2020-02-01", "2020-03-01"}, each _ < "2020-04-01") it returns a list of values.
但是当我使用这个代码时: List.Select({"2020-01-01", "2020-02-01", "2020-03-01"}, each _ < "2020-04-01") 它返回值列表。
First, I assume this is in the context of a function like Table.AddColumn - if that is so, then the cause of your error is: you are referencing the inner function's list item parameter instead of the outer function's table record parameter with the "[Date4]" reference.首先,我假设这是在 Table.AddColumn 之类的函数的上下文中 - 如果是这样,那么您的错误原因是:您正在引用内部函数的列表项参数而不是外部函数的表记录参数[Date4]”参考。
The fix is easier to see once you expose the full code under the syntax sugar involved: simply use a different identifier for your inner parameter.一旦您在所涉及的语法糖下公开完整代码,就更容易看到修复:只需为您的内部参数使用不同的标识符。
List.Select(
{[Date1],[Date2],[Date3]},
(ListItem)=> ListItem < [Date4]
)
How does the above work?以上是如何工作的? Look at the full M code of the original for an idea, again assuming we are using a function like Table.AddColumn:
查看原始的完整 M 代码以获得一个想法,再次假设我们正在使用 Table.AddColumn 之类的函数:
= Table.AddColumn(
Table1,
"New Column Name",
each List.Select(
{[Date1],[Date2],[Date3]},
each _ < [Date4]
)
)
We can see there are actually two each's at play.我们可以看到实际上有两个在玩。 Three points to help us understand the problem:
三点帮助我们理解问题:
With the above points, we can rewrite the code as follows有了以上几点,我们可以将代码改写如下
= Table.AddColumn(
Table1,
"New Column Name",
(_)=> List.Select(
{_[Date1],_[Date2],_[Date3]},
(_)=> _ < _[Date4]
)
)
Now you can see there is an outer "_" referencing each row of the table as a record which allows us to access the fields with for example "_[Date1]".现在您可以看到有一个外部“_”将表的每一行作为记录引用,它允许我们访问带有例如“_[Date1]”的字段。 The inner "_", on the other hand, is accessing each value of the input list.
另一方面,内部“_”正在访问输入列表的每个值。 So, in the context of the innermost function, "_ < _[Date4]", the "_" refers to only the inner "_" - ie you are trying to access a record field from a date value, causing an error.
因此,在最内层函数“_ < _[Date4]”的上下文中,“_”仅指内部的“_” - 即您试图从日期值访问记录字段,从而导致错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.