Forum Discussion

Mischi's avatar
Mischi
Frequent Visitor
3 years ago
Solved

Formatting Date

Hello. Our company works in Periods (a period of 4 weeks, not nessecarily lining up with a month) and I need to format a date value accordingly. If a date is on or in between 21. May 2023 and 17. J...
  • grazitti_sapna's avatar
    3 years ago

    Hey, 

    You can perform this task by creating a new column and by after that using DAX formula 

    PeriodCode = 

    VAR CurrentDate = YourTableName[DateColumn]

    VAR StartDate = DATE(2023, 5, 21)  // Update with your desired start date

    VAR DaysDiff = DATEDIFF(StartDate, CurrentDate, DAY)

    VAR PeriodNumber = CEILING(DaysDiff / 28, 1)

     

    RETURN

        SWITCH(

            TRUE(),

            AND(DaysDiff >= 0, DaysDiff < 28), "P" & PeriodNumber,

            AND(DaysDiff >= 28, DaysDiff < 56), "P" & (PeriodNumber + 1),

            AND(DaysDiff >= 56, DaysDiff < 84), "P" & (PeriodNumber + 2),

            // Add more cases for other periods as needed

            "Unknown"

        )

    After that in modeling tab change the format into text and after using the new calculated column you can achieve your desired output.

    Thank you. Hope this will help.