Search code examples
powerbim

Power BI - Does October 1st Fall Between Two Dates


Given a "start date" column and an "end date" column, how can I create a calculated column that returns "TRUE" if October 1st falls between those two dates?


Solution

  • Assuming that start date is always before end date and that dates can span more than 1 year, I would do it like this in 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"
    

    This produces the following result: enter image description here