Forum Discussion

jpt1228's avatar
jpt1228
Icon for Responsive Resident rankResponsive Resident
8 years ago
Solved

Adding customer specific date to date dim

Hello, am building a data model for a national retailer and in their system they report the date as Year Month Week and Week Number as formatted below:     I want to convert this to a date t...
  • v-ljerr-msft's avatar
    v-ljerr-msft
    8 years ago

    Hi jpt1228,

     

    My mistake! The formula below should work. :smileyhappy:

    Column = 
    VAR year =
        VALUE ( LEFT ( Table1[Customer Date], 4 ) )
    VAR month =
        SWITCH (
            MID ( Table1[Customer Date], 6, 3 ),
            "Jan", 1,
            "Feb", 2,
            "Mar", 3,
            "Apr", 4,
            "May", 5,
            "Jun", 6,
            "Jul", 7,
            "Aug", 8,
            "Sep", 9,
            "Oct", 10,
            "Nov", 11,
            "Dec", 12,
            0
        )
    VAR weekno =
        VALUE ( RIGHT ( Table1[Customer Date], 1 ) )
    VAR firstDateOfMonth =
        DATE ( year, month, 1 )
    VAR weeknum =
        WEEKNUM ( firstDateOfMonth, 2 )
    RETURN
        CALCULATE (
            LASTDATE ( 'Date'[Date] ),
            FILTER ( 'Date', WEEKNUM ( 'Date'[Date], 2 ) = weeknum + weekno - 1 && YEAR('Date'[Date])=year)
        )

    Regards