Forum Discussion

spehe's avatar
spehe
Helper I
2 years ago
Solved

Convert date format 'YYww' to FirstDateOfWeek

Hello, I have a column with data containing the last two digits of a year and a two digit week number. I would like to add a new column called FirstDateOfWeek where the first date of the specified we...
  • FreemanZ's avatar
    2 years ago

    hi spehe ,

     

    The gpt code is for Power Query and Ibendlin's code is for a calculated column with DAX. You may also try the following:

    FirstWeekDate = 
    VAR _year = 20&LEFT([date], 2)
    VAR _yearstart = WEEKDAY(DATE(_year, 1, 1), 2)
    VAR _week = RIGHT([date], 2)
    VAR _days = _week*7 - _yearstart +1
    RETURN DATE(_year, 1, 1)+_days

    it worked like:

     

    about how to add calculated columns:

    https://learn.microsoft.com/en-us/power-bi/transform-model/desktop-calculated-tables