Forum Discussion

Birinder's avatar
Birinder
Helper III
4 years ago
Solved

How to add 2 date columns into a 3rd column.

Hi there,  I am doing this in excel and it works extremely fine.   Suppose I have 2 columns of dates. Date is in MM/DD/YYYY format. Imagine 1st column has value of 01/01/2016 and 2nd has value of...
  • Jakinta's avatar
    4 years ago

    Here is one way to do it.

    The key was to convert dates to numbers.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjTQN9Q3MlTSAbGMwcxYHaCwIVzYUN/YAC5sBBc2gqmOBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Date1 = _t, Date2 = _t]),
        ToDate = Table.TransformColumnTypes(Source,{{"Date1", type date}, {"Date2", type date}}),
        #"Changed Type" = Table.TransformColumnTypes(ToDate,{{"Date2", type number}, {"Date1", type number}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Date3", each ([Date1]+[Date2])/2, type number),
        #"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Date1", type date}, {"Date2", type date}, {"Date3", type date}})
    in
        #"Changed Type1"