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
mihaigm
Frequent Visitor

Calendar table with custom column -> first day of year on Saturday

Hello everyone!!!
I need to create a calculated Data Table in DAX that has also a "custom date" column that always starts the new year with the last Saturday of the previous year.

Eg:

- Dicember 30th 2023 (real date) = January 1st 2024 (custom date).

- Dicember 28th 2024 (real date) = January 1st 2025 (custom date).

 

So, I've  already created the standard calendar table in DAX, but I'm having trouble in creating the "custom date" column..

Any idea how to do it? Thank you so much!

 

3 REPLIES 3
bhanu_gautam
Super User
Super User

@mihaigm , Try using this to create new column

 

CustomCalendar =
ADDCOLUMNS (
Calendar,
"CustomDate",
VAR CurrentYear = YEAR([Date])
VAR LastSaturdayOfPrevYear =
CALCULATE (
MAX ( Calendar[Date] ),
Calendar[Year] = CurrentYear - 1,
Calendar[Weekday] = 6 -- 6 means Saturday
)
VAR DaysSinceLastSaturday = DATEDIFF ( LastSaturdayOfPrevYear, [Date], DAY )
RETURN
IF (
[Date] >= LastSaturdayOfPrevYear,
DATE ( CurrentYear, 1, 1 ) + DaysSinceLastSaturday,
DATE ( CurrentYear - 1, 1, 1 ) + DaysSinceLastSaturday
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Thank you so very much @bhanu_gautam for your quick answer!!! But, unfortunately still returns an error... could you have a simple Date Table code also with the "custom column" in it??

Hi All,
Firstly  bhanu_gautam thank you for your solution!

And @mihaigm ,According to your needs, you want to customize a new calculated column to achieve your needs, right?
Then you can try the code, hope it helps you:

Custom Date = 
VAR CurrDate = 'Calendar'[Date]
VAR CurrYear = YEAR(CurrDate)
VAR EndOfYearCurrent = DATE(CurrYear, 12, 31)
VAR EndOfYearPrev = DATE(CurrYear - 1, 12, 31)
VAR LastSatCurrent =
    EndOfYearCurrent - MOD(WEEKDAY(EndOfYearCurrent) - 7, 7)
VAR LastSatPrev =
    EndOfYearPrev - MOD(WEEKDAY(EndOfYearPrev) - 7, 7)
VAR CustomYear =
    IF(CurrDate >= LastSatCurrent, CurrYear + 1, CurrYear)
VAR CustomStart =
    IF(CurrDate >= LastSatCurrent, LastSatCurrent, LastSatPrev)
RETURN
    DATE(CustomYear, 1, 1) + (CurrDate - CustomStart)

vxingshenmsft_0-1739155718308.pngvxingshenmsft_1-1739155756999.png

If you have any other questions, you can check out the pbix file I uploaded, I hope it helps, and I'd be honored if I could solve your problem!

Hope it helps!

Best regards,
Community Support Team_ Tom Shen

If this post helps then please consider Accept it as the solution to help the other members find it more quickly.




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! Prices go up Feb. 11th.

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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