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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
DebbieE
Community Champion
Community Champion

Created Date table with DAX but Dates are from 1899

I have created a DAX table using CALENDARAUTO But I dont want a date table with dates previous to what is in my data. I dont need dates from 1899. Is there any way I can have a date table that starts at say the start of your data set and ends at the end of the year of your data set? 

 

Dim Date = VAR BaseCalendar = CALENDARAUTO(12)
RETURN GENERATE (
BaseCalendar,
VAR BaseDate = [DATE]
VAR YearDate = YEAR( BaseDate)
VAR MonthNumber = FORMAT(MONTH( BaseDate),"00")
VAR MonthName = FORMAT(DATE(1,MonthNumber,1),"MMMM")
VAR DayOfWeek = WEEKDAY(BaseDate)
VAR WeekDay = FORMAT(BaseDate,"DDDD")
VAR WeekNo = WEEKNUM(BaseDate)
VAR Quarter = ROUNDUP(Month(BaseDate)/3,0)
RETURN ROW (
"DateKey",YearDate&MonthNumber&FORMAT(DAY(BaseDate),"00"),
"Day", FORMAT(DAY(BaseDate),"00"),
"Year",YearDate,
"Quarter",Quarter,
"Month No", MonthNumber,
"Month",MonthName,
"Day of Week", DayOfWeek,
"Week Day",WeekDay,
"WeekNo", WeekNo
))
 
 
1 ACCEPTED SOLUTION
DebbieE
Community Champion
Community Champion

Yes, that is what I looked at and as I said, I still didnt understand how to apply that to what I already had set up.  Ive decided to not use a DAX Table for dates for the following reasons.

 

Every time I add a new fields into the Date table all my visuals reset from the date hierarchy to the date causing my visuals to error until I go through and change everything back to hierarchy, I dont want this to happen when I decide to add a new column.

 

Every time I decide to use the Date table the full DAX code appears in its window and I have to re hide it. This is really annoying when your trying to use fields from the date table

 

So for this Ive decided to create the date time dimension in my database as a table

View solution in original post

10 REPLIES 10
parry2k
Super User
Super User

@DebbieE  you can use calendar DAX function to create calendar table and give min and max date from your data table



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

DebbieE
Community Champion
Community Champion

I wanted the date to be dynamic and grow without having to hardcode the dates

I tried this

CALENDAR (MINX (), MAXX ())
 
But It wont allow me to add my dates to into () when I try and I dont understand why?
(As it when I start adding Start Date It doesnt come through for me to select)
 
 

@DebbieE assuming you have transaction table with date field in it, this is wht you need to do

 

calendar = 
var startDate = MIN( TranTable[Date] )
var endDate = MAX( TranTable[Date] )
RETURN
CALENDAR(  startDate, endDate)

and then you can add other fields as required. I hope it helps.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

DebbieE
Community Champion
Community Champion

Im struggling to understand how the above is used to change what I have now Ive hard coded dates

Dim Date = VAR BaseCalendar = CALENDAR (DATE (2017, 1, 1), DATE (2020, 12, 31))
RETURN GENERATE (
BaseCalendar,
VAR BaseDate = [DATE]
VAR YearDate = YEAR( BaseDate)
VAR MonthNumber = FORMAT(MONTH( BaseDate),"00")
VAR MonthName = FORMAT(DATE(1,MonthNumber,1),"MMMM")
VAR DayOfWeek = WEEKDAY(BaseDate)
VAR WeekDay = FORMAT(BaseDate,"DDDD")
VAR WeekNo = WEEKNUM(BaseDate)
VAR Quarter = ROUNDUP(Month(BaseDate)/3,0)
RETURN ROW (
"DateKey",YearDate&MonthNumber&FORMAT(DAY(BaseDate),"00"),
"Day", FORMAT(DAY(BaseDate),"00"),
"Year",YearDate,
"Quarter",Quarter,
"Month No", MonthNumber,
"Month",MonthName,
"Day of Week", DayOfWeek,
"Week Day",WeekDay,
"WeekNo", WeekNo
))

@DebbieE I guess your question is why calendar and calendarauto workign differently? Not sure what your question is? Since you hard coded the date range, you are getting calendar for that period, whereas calendarauto, automatically calculates the date range from your dataset



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

DebbieE
Community Champion
Community Champion

This was my question,

 

To get it working I had hard coded the values for CALENDAR which works but its not really what I want

I wasnt sure how to transform what I already have into something thats using a minimum and a maximum date from my data.

 

I saw the DAX provided but still didnt understand how I could do this. I understand why Calendar and Calendar AUTO work differently.

@DebbieE did you saw my reply on how to get min and max date which then you can pass to calendar function instead of hard coding.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

DebbieE
Community Champion
Community Champion



Yes, that is what I looked at and as I said, I still didnt understand how to apply that to what I already had set up.  Ive decided to not use a DAX Table for dates for the following reasons.

 

Every time I add a new fields into the Date table all my visuals reset from the date hierarchy to the date causing my visuals to error until I go through and change everything back to hierarchy, I dont want this to happen when I decide to add a new column.

 

Every time I decide to use the Date table the full DAX code appears in its window and I have to re hide it. This is really annoying when your trying to use fields from the date table

 

So for this Ive decided to create the date time dimension in my database as a table

@DebbieE i'm sorry  but not fully sure what was actual issue, may be it is me and not understanding the problem. since you already resolved it but i would still like to know more about the issue, is it possible for you to take screen shot and if possible to share pbix file to look into it further.

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

DebbieE
Community Champion
Community Champion

Yes, that is what I looked at and as I said, I still didnt understand how to apply that to what I already had set up.  Ive decided to not use a DAX Table for dates for the following reasons.

 

Every time I add a new fields into the Date table all my visuals reset from the date hierarchy to the date causing my visuals to error until I go through and change everything back to hierarchy, I dont want this to happen when I decide to add a new column.

 

Every time I decide to use the Date table the full DAX code appears in its window and I have to re hide it. This is really annoying when your trying to use fields from the date table

 

So for this Ive decided to create the date time dimension in my database as a table

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.