Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Two value types in one column

Hi! I have two columns in a self-referencing table tracker, both with dates (01/12/2020 format) and strings (e.g. “Pending”). How to preserve both different types considering that another column make...
  • v-frfei-msft's avatar
    6 years ago

    Hi Anonymous ,

    We can create a custom column like that.

    if [R date] = "Pending" then 0 else Duration.Days([F date]-Date.FromText([R date]))

    M query for your reference.

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("Vc87CoAwEADRu6QOJLv538I+pFPEJvcvFUUcy+FV07tZtrkeczfWiBNx6tWbYftV+sQNSgiAQIiASEiARMiATCiAQqiASmiARhD/ifqfCOR9Hyc=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"R date" = _t, #"F date" = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"R date", type text}, {"F date", type date}}),
        #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each if [R date] = "Pending" then 0 else Duration.Days([F date]-Date.FromText([R date])))
    in
        #"Added Custom"