Forum Discussion

SharpsmartCP's avatar
SharpsmartCP
Frequent Visitor
5 years ago
Solved

Using the DATEADD expression with an unusual data set

Good morning, I have a data set as follows: 1 x Column of dates 1 x Column that is an identifier for a date frequency. eg. 103 represents every third week, 104 represents every forth week, etc. but...
  • Mohammad_Refaei's avatar
    Mohammad_Refaei
    5 years ago

    The challenge here is that DATEADD reutns a date column with the exisiting dates only. As you are using a denormalized structure without a calendar table (you might want to consider this practice) then you may use 2 solutions:

    1. Use the simple math like:

     

    Next Scheduled Date =
    SWITCH (
        [TYPE ADD],
        "DAY", [SCH01_LD1] + [DAYS TO ADD],
        "MONTH",
            [SCH01_LD1] + [DAYS TO ADD] * 30,
        "YEAR",
            [SCH01_LD1] + [DAYS TO ADD] * 365
    )

     

     

    2. Use Power Query (Preferred):

    In Power Query add a new column

    if [TYPE ADD] = "DAY" then Date.AddDays([SCH01_LD1],[DAYS TO ADD]) else
    if [TYPE ADD] = "WEEK" then Date.AddWeeks([SCH01_LD1],[DAYS TO ADD]) else
    if [TYPE ADD] = "MONTH" then Date.AddMonths([SCH01_LD1],[DAYS TO ADD]) else
    if [TYPE ADD] = "YEAR" then Date.AddYears([SCH01_LD1],[DAYS TO ADD])