Forum Discussion

kalspiros's avatar
kalspiros
Helper I
4 years ago
Solved

Create new table based on dates

Hi all   Cheeky question: Here's the table with the current information: PROJECT ID ACCEPTED DATE DEADLINE PROJECT PRICE 12345 25/11/2021 28/11/2021 £8,000 23456 12/03/2015 11/03...
  • BA_Pete's avatar
    4 years ago

    Hi kalspiros ,

     

    In Power Query, go to New Source>Blank Query then in Advanced Editor paste my code over the default code. You can then follow the steps I took to complete this:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("TcuxDcBACEPRXaiRwHAk7IJuumySyQJXpfzWcxXBfAUxWQggpoaJ/MX7JKsqbS4afPUGE/UGmGvTE+ZHg2Mp39mP/QE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"PROJECT ID" = _t, #"ACCEPTED DATE" = _t, DEADLINE = _t, #"PROJECT PRICE" = _t]),
        chgTypes = Table.TransformColumnTypes(Source,{{"PROJECT ID", Int64.Type}, {"ACCEPTED DATE", type date}, {"DEADLINE", type date}, {"PROJECT PRICE", Currency.Type}}),
        addDaysBetween = Table.AddColumn(chgTypes, "daysBetween", each Duration.Days([DEADLINE] - [ACCEPTED DATE]) + 1),
        addDailyPrice = Table.AddColumn(addDaysBetween, "dailyPrice", each [PROJECT PRICE] / [daysBetween]),
        addDateList = Table.AddColumn(addDailyPrice, "dateList", each List.Transform({Number.From([ACCEPTED DATE])..Number.From([DEADLINE])}, each Date.From(_))),
        expandDateList = Table.ExpandListColumn(addDateList, "dateList")
    in
        expandDateList

     

    SUMMARY:

    1) Get days between dates

    2) Divide [PROJECTPRICE] by days to get daily value

    3) Create list of dates between accpted/deadline dates

    4) Expand list

     

    This give me the following output:

     

    Pete