Forum Discussion

gaikwadaa123's avatar
gaikwadaa123
Helper II
5 years ago
Solved

Date and day subtraction.

Hello I have two columns in the data, 

One is Date and another one is DA which is day ahead as below. I want to add another custome column as EndDate which will subtstract the Date -DA= EndDate.  for example when date is 01/01/2020 and DA is zero EndDate will be  01/01/2020 which is same. When DA is 1 EndDatewill be 31/12/2019, when DA is 2 EndDate will be 30/12/2019. When it is DA is 3 EndDate will be 29/12/2019 so on.  I have max DA till 5 in data. 

I do not want calculated column but want custom column. Thank you in advance. I am new to PB so it would be good if you send the code using my column names. 

 

  • smpa01's avatar
    smpa01
    5 years ago
    #"Added Custom" = Table.AddColumn(#"Changed Type", "End Date", each Date.AddDays([Date],[DA]*-1))

8 Replies

  • smpa01's avatar
    smpa01
    Community Champion
    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMtQ31DcyMDJQ0lEyUIrVQREwRBcwQhcwRhcwQRcwVYqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Column1 = _t, Column2 = _t]),
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type date}, {"Column2", Int64.Type}}),
        #"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1", "Date"}, {"Column2", "DA"}}),
        #"Added Custom" = Table.AddColumn(#"Renamed Columns", "Custom", each Date.AddDays([Date],[DA]*-1))
    in
        #"Added Custom"
    • gaikwadaa123's avatar
      gaikwadaa123
      Helper II

      Thank you for the response. Appreciate it. Can you send me by adding the source? I get error when I paste my source. 

       

      • smpa01's avatar
        smpa01
        Community Champion

        which one is Date column and which one is DA column in

        Table.TransformColumnTypes(#"Promoted Headers",{{"DailyMAPE_Load", Percentage.Type}, {"DailyMAE_Load", type number}})