Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
jpt1228
Responsive Resident
Responsive Resident

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:

 

image.png

 

I want to convert this to a date the date tables can recognize. I think the simplest way is going to be to create a helper table where I build in excel and import between the model date table and the retailer fact table.

 

Here is what their calendar looks like

 

image.png

1 ACCEPTED SOLUTION

Hi @jpt1228,

 

My mistake! The formula below should work. Smiley Happy

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

View solution in original post

6 REPLIES 6
v-ljerr-msft
Microsoft Employee
Microsoft Employee

Hi @jpt1228,

 

I assume you already have an individual and continuous Calendar table called "Date" like below.

 

t1.PNG

 

Then you should be able to use the formula below to create a calculate column in your data table to convert the custom date to a normal date. 

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 )
    )

c1.PNG

 

Regards

Hi @v-ljerr-msft - This is partially working. I am able to convert into month and day. However the Year is coming in as 2025 rather than 2017.  I just created the calendar table from 2000-2025

 

image.png

 

Target Date to DateDim =
VAR year =
VALUE ( LEFT ( 'Customer Sales'[Target Date], 4 ) )
VAR month =
SWITCH (
MID ( 'Customer Sales'[Target 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 ( 'Customer Sales'[Target Date], 1 ) )
VAR firstDateOfMonth =
DATE ( year, month, 1 )
VAR weeknum =
WEEKNUM ( firstDateOfMonth, 2 )
RETURN
CALCULATE (
LASTDATE ( 'DateDim'[Date] ),
FILTER ( 'DateDim', WEEKNUM ( 'DateDim'[Date], 2 ) = weeknum + weekno - 1 )
)

Hi @jpt1228,

 

My mistake! The formula below should work. Smiley Happy

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

Such smart people here. That works

 

Thanks @v-ljerr-msft

As an FYI, there are numerous blog discussions around create custom calendars. It's typically done on the query side. Here are some examples:

https://www.excelguru.ca/blog/2016/01/06/creating-a-custom-calendar-in-power-query/

 

https://powerpivotpro.com/category/skill-areas/custom-calendars/

jpt1228
Responsive Resident
Responsive Resident

Hi @Peter_R I'm not sure I follow your logic. I don't think I need to crerate a custom calendar as much as convert text and numerals to a calendar date. @v-ljerr-msft Got me close to what I am looking for but the year was not coming in correctly. That is what I am looking to resolve.

 

Thanks

 

Jon

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.