Forum Discussion

Apssawhney's avatar
Apssawhney
New Member
5 years ago
Solved

Create Custom Calender Table With info for custom dates

Hi Team,   Can you help in creating a calendar table which has all the dates but few dates per month are marked based on the below conditions -    1. Microsoft Patch released (2nd Tuesday of ever...
  • StefanoGrimaldi's avatar
    5 years ago

    hey,

     

    Column =
    var weeknum1 = (1 + WEEKNUM ( 'Table'[Date] )-WEEKNUM( STARTOFMONTH ('Table'[Date]))) //finds the weeknumber
    var daynumber = WEEKDAY('Table'[Date],2) //tuesdays in this format its number 2
    var out = IF( AND(weeknum1=2,daynumber=2),"Microsoft Patch released",IF(AND(weeknum1=2,daynumber=4),"Non-prod servers patching",IF(AND(weeknum1=2,daynumber=5),"Work stations patching for UAT Machines","")))

    return out
     
    with this logic you can add the other parameters to give the wanted output but basically the 2 variable get the exact number of the week and weekday and month weeknum 
     
    if this heleped give some kudos, and if solved your question mark as answer for others to find. 
  • Icey's avatar
    5 years ago

    Hi Apssawhney ,

     

    How do you get this?


     

    Date Activity
    21/01/2021 Prod servers patching/Work stations production patching
    22/01/2021 Prod servers patching/Work stations production patching
    23/01/2021 Prod servers patching/Work stations production patching

     


    When I create column based on your logic, the result is like below:

     

    DAX:

     

    Activity =
    VAR YearWeek_ =
        WEEKNUM ( [Date], 2 )
    VAR StartofMonthWeek_ =
        WEEKNUM ( STARTOFMONTH ( 'Calendar (DAX)'[Date] ), 2 )
    VAR MonthWeek_ = YearWeek_ - StartofMonthWeek_ + 1
    VAR WeekDay_ =
        WEEKDAY ( [Date], 2 )
    VAR Month_ =
        MONTH ( [Date] )
    VAR Day_ =
        DAY ( [Date] )
    RETURN
        SWITCH (
            TRUE (),
            MonthWeek_ = 2
                && WeekDay_ = 2, "Microsoft Patch released",
            MonthWeek_ = 2
                && WeekDay_ = 4, "Non-prod servers patching",
            MonthWeek_ = 2
                && WeekDay_ = 5, "Work stations patching for UAT Machines",
            MonthWeek_ = 3
                && WeekDay_ = 5, "Prod servers patching / Work stations production patching",
            Month_ = 12
                && Day_ >= 25
                && Day_ <= 30, "Freeze Period"
        )
    

     

     

    M:

     

    let
        StartDate = #date(2021,1,1),
        EndDate = #date(2021,12,31),
        DayCount = Duration.Days(Duration.From( EndDate - StartDate )),
        Source = List.Dates(StartDate,DayCount,#duration(1,0,0,0)),
        TableFromList = Table.FromList(Source, Splitter.SplitByNothing()),   
        ChangedType = Table.TransformColumnTypes(TableFromList,{{"Column1", type date}}),
        RenamedColumns = Table.RenameColumns(ChangedType,{{"Column1", "Date"}}),
        #"Added Custom" = Table.AddColumn(RenamedColumns, "Activity", each let 
    MonthWeek_ = Date.WeekOfMonth ([Date],1),
    WeekDay_ = Date.DayOfWeek ( [Date], 2 ),
    Month_ = Date.Month([Date]),
    Day_ = Date.DayOfWeek([Date],1)
    in 
    if MonthWeek_ = 2
    then if WeekDay_ = 2 then "Microsoft Patch released" else if WeekDay_ = 4 then "Non-prod servers patching" else if WeekDay_ = 5 then "Work stations patching for UAT Machines" else null 
    else if MonthWeek_ = 3 and WeekDay_ = 5 then "Prod servers patching / Work stations production patching" else if Month_ = 12 and Day_ >= 25 and Day_ <= 30 then "Freeze Period" else null)
    in
        #"Added Custom"

     

     

     

    Best Regards,

    Icey

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.