Extended Date Table (Power Query M function)

Hi @ericet,

Welcome to the Forum, great to have you here.

I’m afraid not, that’s just the initial naming of the column. Thing is that once a column has been created it can be reference by its name in square brackets so “Date” becomes [Date] for example.

I think there are two ways you can approach this either copy the entire script to a text editor / visual studio code and first replace the column name like “Date” followed by a replace all of the text [Date]
OR
Keep it as is and rename all columns after you’ve invoked the function.
You can even choose to copy that Table.RenameColumns step back to the function for future use.

I hope this is helpful.

1 Like

Thanks for the quick reply, looking at the code in more détail, I do not see Monday, Tuesday, Wednesday etc for the name of the days ?

1 Like

Correct those are created with an M function, you can check in the PBIX file settings if that’s set to your region.

1 Like

Found a great YouTube with a link to download a PBIX file that has exactly what I need. So, I don’t have to reinvent the wheel. https://youtu.be/jpZ96T3wdjc

I would have prefered your calendar but time is pressing maybe someone already made different language versions of your script.

Thanks

2 Likes

GREAT!!!
I’ve been waiting for some time to come across a date table with FY details built into it…

3 Likes

Hi @Melissa. Thank you very much for this.

Could you perhaps add Fiscal Week? (please)

I know I may be pushing my (our) luck here… but could you possibly add Fiscal Week to your Power Query script? I have a solution in the form of a calculated column, but I’d really like to keep everything within one (your) script.

I’ve added “MonthInitial” and “DayOfWeekInitial”

(If you like it, feel free to add these columns to your script. I love the cleaner visuals)
– These columns sort correctly as I use zero-width invisible characters where there are duplicate values, eg “J” for Jan, June, July )

Script

script__with_MonthInitial_&_DayOfWeekInitial.txt (8.7 KB)
(this is Melissa’s script with renaming to suit me… as well as adding the two columns described above. It may be safer to just add these columns to her original script rather than use mine)

2 Likes

@michellepace Can you please share how you did that in DAX?

1 Like

Hi Antriksh (@AntrikshSharma). It’s funny you ask that. I can’t claim the fame for coming up with this, but when I first saw it - - it was in DAX – but I needed to have it in SQL. Needless to say this now comes in all three flavors because I’ve converted the original Dax to both M-Code (see script above) as well as SQL - - see here for DAX and SQL: https://community.powerbi.com/t5/Desktop/Single-letter-month-abbreviations/m-p/462132.

2 Likes

@michellepace Haha, we all learn everyday, actually for some reason my visuals weren’t grouping and showed duplicate values, entered same code again and again and then it started working, thanks for sharing !

1 Like

@michellepace,

Love that invisible characters trick to address the duplicate name issue. Saw Ferrari do that in a video last year, and thought it was one of the coolest DAX tricks I’d ever seen.

Really like the way you’ve applied it to the single letter month names.

  • Brian
1 Like

Hi @michellepace,

I’ve got solutions for the MonthInitial and DayOfWeekInitial columns.
I’ll look into the Fiscal Week requirement and get back to you, hopefully later today.

4 Likes

@michellepace

Added the Fiscal Week based on the logic you’ve provided, see this article, it requires a FYStartMonth and FYStartOfWeekDayName . Note that this can create partial weeks around the FY Start and End date. And another thing to note, that in the DAX code there’s a misalignment in FY this is sorted in the M code.

image

Also added MonthInitial and DayOfWeekInitial columns that use the the M function Character.FromNumber to add a unicode Zero-Width Space character if a letter isn’t distinct.

@BrianJ,
if you want to update the Cheat Sheet for Extended Date Table.
MonthInitial should be sorted by MonthOfYear and
DayOfWeekInitial sorted by DayOfWeek

4 Likes

@Melissa,

Thanks – that’s fantastic. Biggest upgrade to the date table in a long time. I will do a major overhaul of the cheat sheet this week, and add the information for how to sort each column. Once done, I will post it and at that point I think doing a video to highlight both would be great.

  • Brian
1 Like

Hi @Melissa and @BrianJ,

I think there may be a little mistake in the iso weeks. Sorry, I don’t mean to dig for mistakes. It’s the first time “iso weeks” has ever been important to me. I’ve just started doing some work for a company who speaks completely in “weeks like we see on our desk calendars” haha. Which is iso weeks.

I copied Melissa’s latest script into the attached pbix (with no changes at all). When you get a moment could you please have a quick look? Happy to be corrected but the below looks a little off. I added comments in the hope you’ll see a pattern and get a good idea of where the m-code error could be… my m-coding leaves much to be desired (still) :flushed:.


Dates_IsoWeekCheck.pbix (113.4 KB)

Thanks once again for this!
Michelle

1 Like

Hi @michellepace,

Thanks for your feedback, I appreciate it.
However I don’t see an issue with the ISO Weeks, so I suspect you’ve selected the “Year” field instead of the "ISO Year" field and that has gotten you into trouble… :wink:

Only the boundaries of the date range can cause a partial first- and or last week in the Date table. Let me know if that solves it for you.

1 Like

So it is the initial code that keeps getting updated in this thread with the revisions - I couldn’t see an edited flag but looked to be.

On the topic of the Day initials, a stand-alone Short Month Name - eg Jan, Feb is something that i often use. atm, it is concatenated in the Month & Year column.

1 Like

Hi @Cameron,

Yes to prevent you from having to search through a lengthy thread, to locate the latest version, I always update the initial post. So if you always copy the code from there you can take advantage of the latest modifications and/or updates as soon as they’ve become available.

Now also included the MonthShortName

.

@michellepace and @BrianJ,

Just added the sort by column FWeeknYear

3 Likes

@Melissa,

Thanks for the heads up. I was just working on the cheat sheet a few minutes ago, and will incorporate the new fields and sort fields tomorrow. Was going to ask Karen if she could work her graphic design magic on the cheat sheet, so that we’ll have a really nice, Enterprise DNA branded version.

  • Brian
2 Likes

Hi @michellepace,

The QuarterCompleted is already in the Date table and instead of a YearCompleted you could use the YearOffset <0. Nice to see you’re putting the Date table to good use :+1:

1 Like

Hi @Melissa.

REQUEST: please add “ISO Quarter”
I really love this dates table. It is fantastic. May I ask you to add one last little tweak in that you add ISO Quarter too?

WHY?
I’d like to build a Date hierarchy with ISO year, ISO quarter and ISO week. As your Quarter field is based on the Gregorian calendar, it does not tie up when I use my ISO Year. For instance, looking at ISO year 2020 which started on the 30th of December:
image

ABOUT ISO Quarters
(just some additional info for everyone to read)

ISO-8601 calendars have a consistent number of weeks in each quarter and a consistent number of days each week, making the ISO-8601 calendar popular when calculating retail and financial dates.

The first three quarters in the ISO-8601 always have 13 weeks in them, with the last Quarter having either 13 or 14 weeks in it, depending upon the start of the next ISO-8601 year.

https://help.tableau.com/current/pro/desktop/en-gb/dates_calendar.htm

Thank you, really this is going to be forever useful.
Michelle

1 Like