PowerBI:按日期过滤

时间:2017-01-17 17:56:31

标签: powerbi powerquery m

我有一个查询,我想根据我创建的新日期列过滤。

基本上,接受比该日期早42天的任何事情。

我已尝试按日期过滤,然后将其减去42,但它不起作用?

let
    #"SQL-JM" = let
    Source = Sql.Databases("xxx.xxx.xxx.xxx"),
    MNH = Source{[Name="DBT"]}[Data],
    #"DBO-JM" = DBT{[Schema="dbo",Item="DBO-JM"]}[Data]
in
    #"DBO-JM",
    #"Added Custom1" = Table.AddColumn(#"DBO-JM", "Start_of_QTR", each Date.StartOfQuarter(DateTime.LocalNow())),
in
    #"Filtered Rows"

2 个答案:

答案 0 :(得分:2)

如果我正确理解您的任务,您根本不需要自定义列。

我会这样做:

let
    #"SQL-JM" = let
    Source = Sql.Databases("xxx.xxx.xxx.xxx"),
    MNH = Source{[Name="DBT"]}[Data],
    #"DBO-JM" = DBT{[Schema="dbo",Item="DBO-JM"]}[Data],
    GetFilterDate = Date.From(Date.StartOfQuarter(DateTime.LocalNow())), //You can use any logic to get that date
    FilterRows = Table.SelectRows(#"DBO-JM", each [DateStamp] < GetFilterDate) //You can also add some modifications to GetFilterDate using each row's values, if you need
in
    FilterRows

答案 1 :(得分:1)

假设您希望按DateStamp列进行过滤,比Start_of_QTR提前42天,您可以在#&#34之后添加以下行;添加Custom1&#34;行:

#"Filtered Rows" = Table.SelectRows(#"Added Custom1", each [DateStamp] < Date.AddDays([Start_of_QTR], -42))