March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hello,
I want to create a date table but in my original dataset I don't have a date. I only have weeknumber & year. Do i need to add the dates in the date table? If I do so the weeknumber & year are not unique. I am afraid that this gives errors with the relationships.
Can I create a date table with only weeknumbers as the lowest level?
Thanks!
Maartje
Solved! Go to Solution.
@Anonymous
1) Using a Date Table:
You could create a Date table following the method suggested by @negi007 , though you would need to add a date in your dataset (could for example be the first date for each week). The advantage of this method is that you can use Time Intelligence Functions in your measures.
To create a Date Table, you can use:
Date Table =
VAR MinYear = MIN('Table'[Year])
VAR MaxYear = MAX('Table'[Year])
RETURN
ADDCOLUMNS(
CALENDAR(DATE(MinYear, 1, 1), DATE(MaxYear, 12, 31)),
"Year", YEAR([Date]),
"WeekNum", WEEKNUM([Date]))
Then create a YearWeek Colum in the Date Table using:
YearWeek = 'Date Table'[Year] * 100 + 'Date Table'[WeekNum]
And you get this table:
Next add the same YearWeek calculated column to your fact table:
And finally, to get a date column in your fact table (in this example, it is the first date of each week), use:
Date =
CALCULATE (
MIN ( 'Date Table'[Date] ),
FILTER ( 'Date Table', 'Date Table'[YearWeek] = EARLIER ( 'Table'[YearWeek] ) )
)
You can then create a relationship between the Date fields from both tables:
2) Using a Period Table as a dimension table
However, if the dataset doesn't contain dates, a date table is arguably "overkill", and you can simply use a period table.
For example, take this sample dataset:
Firstly create a new calculated column to get the period (YearWeek):
You can then create a period table using:
And then create a relationship between the corresponding YearWeek Columns:
I've attached the sample PBIX file for your reference
Proud to be a Super User!
Paul on Linkedin.
@Anonymous
1) Using a Date Table:
You could create a Date table following the method suggested by @negi007 , though you would need to add a date in your dataset (could for example be the first date for each week). The advantage of this method is that you can use Time Intelligence Functions in your measures.
To create a Date Table, you can use:
Date Table =
VAR MinYear = MIN('Table'[Year])
VAR MaxYear = MAX('Table'[Year])
RETURN
ADDCOLUMNS(
CALENDAR(DATE(MinYear, 1, 1), DATE(MaxYear, 12, 31)),
"Year", YEAR([Date]),
"WeekNum", WEEKNUM([Date]))
Then create a YearWeek Colum in the Date Table using:
YearWeek = 'Date Table'[Year] * 100 + 'Date Table'[WeekNum]
And you get this table:
Next add the same YearWeek calculated column to your fact table:
And finally, to get a date column in your fact table (in this example, it is the first date of each week), use:
Date =
CALCULATE (
MIN ( 'Date Table'[Date] ),
FILTER ( 'Date Table', 'Date Table'[YearWeek] = EARLIER ( 'Table'[YearWeek] ) )
)
You can then create a relationship between the Date fields from both tables:
2) Using a Period Table as a dimension table
However, if the dataset doesn't contain dates, a date table is arguably "overkill", and you can simply use a period table.
For example, take this sample dataset:
Firstly create a new calculated column to get the period (YearWeek):
You can then create a period table using:
And then create a relationship between the corresponding YearWeek Columns:
I've attached the sample PBIX file for your reference
Proud to be a Super User!
Paul on Linkedin.
@Anonymous
you can create a date table like below
Proud to be a Super User!
thanks for your quick response. But I don't have (these) dates in my dataset. The lowest level of dates I have in my dataset is weeknumber. Doesn't it matter that I don't have 2020/01/01, 2020/01/02 etc.? If I create a datetable with these dates in it I don't have unique values in the table. Is that a problem?
Thanks!
@Anonymous This will create unique dates for you. You need to specify the lower and upper limit and for each day there would be a one value in the date table. Since date will be primary table for date it will work for all your date columns.
Table 2 = CALENDAR(date(2020,1,1),date(2022,1,31))
Proud to be a Super User!
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
128 | |
90 | |
75 | |
56 | |
53 |
User | Count |
---|---|
200 | |
104 | |
101 | |
67 | |
55 |