Forum Discussion

qwertyh's avatar
qwertyh
Frequent Visitor
5 years ago
Solved

Adding in a Date Column based on Start Date & End Date

Hello, I am trying to add in an inforce date column which will be the date that drives the calculations for this table.  This will expand the table duplicating each row for each unique month-year ...
  • Jakinta's avatar
    5 years ago

    You can try this...

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcnRyNjUyVtJRMtQ31TcyMDJAMA2VYnWilZwcQ4yNTIGiRvqGEFEdJZA0iG0EVuHsGGJqYgQUNtM3BooaWsKZQNNiYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Policy ID" = _t, #"Start Date" = _t, #"End Date" = _t]),
        DateType = Table.TransformColumnTypes(Source,{{"Start Date", type date}, {"End Date", type date}}),
        DateList = Table.AddColumn(DateType, "Inforce Date", each List.Distinct(List.Transform({Number.From([Start Date]) .. Number.From([End Date])}, each Date.StartOfMonth(Date.From(_))))),
        FINAL = Table.ExpandListColumn(DateList, "Inforce Date")
    in
        FINAL