Power BI - 10 月 1 日是否介于两个日期之间

时间:2021-02-05 21:58:45

标签: powerbi m

给定一个“开始日期”列和一个“结束日期”列,如果 10 月 1 日介于这两个日期之间,我如何创建一个返回“TRUE”的计算列?

1 个答案:

答案 0 :(得分:0)

假设开始日期总是在结束日期之前并且日期可以跨越 1 年以上,我会在 m 中这样做:

let
    Src = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("PczRCcBACAPQXfxWSJTS3iyH+69RW23Bn/Bi9haHw7DMD9EOdAtK6hiL/bcKMcbr+Qu8xmVg3WfnzGgXeyTzBg==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Date from" = _t, #"Date to" = _t]),
    #"Date type" = Table.TransformColumnTypes(Src,{{"Date from", type date}, {"Date to", type date}}),
    #"Which 1st october" = Table.AddColumn(#"Date type", "First october to look for", each if #date(Date.Year([Date from]), 10, 1) > [Date from] then #date(Date.Year([Date from]), 10, 1) else #date(Date.Year([Date from]) + 1, 10, 1)),
    #"Is 1st Oct inbetween" = Table.AddColumn(#"Which 1st october", "1st October inbetween", each if [Date to] > [First october to look for] then true else false, type logical
),
    #"Remove temp col" = Table.RemoveColumns(#"Is 1st Oct inbetween",{"First october to look for"})
in
    #"Remove temp col"

这会产生以下结果: enter image description here