Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

M Power Query Column Calculation

Adding a new Custom Column. Want to calculate the number of days to DUE_DATE   = Table.AddColumn(#"Changed Type", "DaysToDueDate", each DateTime.LocalNow()-([DUE_DATE]))   This is producing resu...
  • mlsx4's avatar
    mlsx4
    2 years ago

    Hi Anonymous 

     

    It doesn't have to... This is my complete code:

    let
        Origen = Excel.Workbook(File.Contents("C:\example.xlsx"), null, true),
        Hoja1_Sheet = Origen{[Item="Hoja1",Kind="Sheet"]}[Data],
        #"Encabezados promovidos" = Table.PromoteHeaders(Hoja1_Sheet, [PromoteAllScalars=true]),
        #"Tipo cambiado" = Table.TransformColumnTypes(#"Encabezados promovidos",{{"DUE_DATE", type datetime}, {"Column1", type text}}),
        #"Personalizada agregada" = Table.AddColumn(#"Tipo cambiado", "DaysToDueDate", each Duration.Days(DateTime.LocalNow()-([DUE_DATE])))
    in
        #"Personalizada agregada"

     

    I have used an excel with this data and it is working perfectly:

    Column1 DUE_DATE
    aaa 14/11/2023 11:35
    bbb 21/11/2023 18:10
    ccc

    18/11/2023 13:45

     

    I haven't defined any type for the new column but it shows correctly the result. I think your problem is with some "naming" or missing punctuation...