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

Be 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

Reply
esterdid
Frequent Visitor

Date calendar dax code

Hello,

 

I am completly new to Dax and will appreciate any assistance here. I have come across this dynamic calendar based on DAX and Ifound it very simple to use. the issue is that I need to expand it to inlcude other columns such as Quarters financial YearQuarter etc..

What is the syntax for including the list below in the current code?

YearNumber
DayWeek
WeekNumber
WeekEnding
DayName
CalendarQtr
FinancialQtr
FinancialYr (FY)
MonthName
CalendarMonth

 

Here is the working script at the moment.

 

Dates =
VAR BaseCalendar =
CALENDARAUTO (6)
RETURN
GENERATE (
BASECALENDAR,
VAR BASEDATE = [DATE] VAR DayDate = DAY([DATE])
VAR YEARDATE = YEAR ( BASEDATE )
VAR MONTHNUMBER = MONTH ( BASEDATE )
VAR YEARMONTHNUMBER = YEARDATE * 12 + MONTHNUMBER -1
RETURN ROW (
"DAY", DayDate,
"YEAR", YEARDATE,
"MONTH NUMBER", MONTHNUMBER,
"MONTH", FORMAT ( BASEDATE, "MMMM" ),
"YEAR MONTH NUMBER", YEARMONTHNUMBER,
"YEAR MONTH", FORMAT ( BASEDATE, "MMM YY" )
)
)

 

 

Thanks

D.

1 ACCEPTED SOLUTION

Hi @esterdid

 

I think this might be close 

 

Dates = 
VAR BaseCalendar =
CALENDAR(date(2016,1,1),today())
RETURN
GENERATE (
BASECALENDAR,
VAR BASEDATE = [DATE] VAR DayDate = DAY([DATE])
VAR YEARDATE = YEAR ( BASEDATE )
VAR MONTHNUMBER = MONTH ( BASEDATE )
VAR YEARMONTHNUMBER = YEARDATE * 12 + MONTHNUMBER -1
VAR FINANCIALQTR = SWITCH(
                        TRUE(),
                        MONTH([Date]) IN {7,8,9} , 1 ,
                        MONTH([Date]) IN {10,11,12} , 2 ,
                        MONTH([Date]) IN {1,2,3} , 3 ,  
                        4)
VAR FINANCIALYR = IF( MONTH([Date]) >=7 , YEARDATE , YEARDATE - 1)
RETURN ROW (
"DAY", DayDate,
"YEAR", YEARDATE,
"MONTH NUMBER", MONTHNUMBER,
"MONTH", FORMAT ( BASEDATE, "MMMM" ),
"YEAR MONTH NUMBER", YEARMONTHNUMBER,
"YEAR MONTH", FORMAT ( BASEDATE, "MMM YY" ),
------------------------------
"Week Number",WEEKNUM([Date]),
"Week Ending",[Date] + (6-(WEEKDAY([Date],3))),
"Day Name" , FORMAT([Date],"DDDD"),
"CalendarQtr" , INT(MONTH([Date]) / 4) + 1 ,       
--
"FinancialQtr" , "FYQ" & FINANCIALQTR ,
"FinancialYr" ,"FY" & FINANCIALYR,
"FinancialYrQtr" ,  FINANCIALQTR &  FINANCIALYR             

)
)

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

7 REPLIES 7
Phil_Seamark
Microsoft Employee
Microsoft Employee

Here are some suggestions for a starters,

 

"Week Number",WEEKNUM([Date]),
"Week Ending",[Date] + (6-(WEEKDAY([Date],3))),
"Day Name" , FORMAT([Date],"DDDD"),
"CalendarQtr" , INT(MONTH([Date]) / 4) + 1    

Just add these to your  RETURN ROW function.


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Thanks Phil,

 

those worked, the remaining straight forward as well? expecially working out the financial year (e.g. FY17) and financial year qarters?


FinancialQtr (e.g. FYQ1)

FinancialQtr (e.g. FYQ12017)
FinancialYr (FY17)

 

Thanks 

When does your financial year start?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

It starts in July (07). Thanks

Hi @esterdid

 

I think this might be close 

 

Dates = 
VAR BaseCalendar =
CALENDAR(date(2016,1,1),today())
RETURN
GENERATE (
BASECALENDAR,
VAR BASEDATE = [DATE] VAR DayDate = DAY([DATE])
VAR YEARDATE = YEAR ( BASEDATE )
VAR MONTHNUMBER = MONTH ( BASEDATE )
VAR YEARMONTHNUMBER = YEARDATE * 12 + MONTHNUMBER -1
VAR FINANCIALQTR = SWITCH(
                        TRUE(),
                        MONTH([Date]) IN {7,8,9} , 1 ,
                        MONTH([Date]) IN {10,11,12} , 2 ,
                        MONTH([Date]) IN {1,2,3} , 3 ,  
                        4)
VAR FINANCIALYR = IF( MONTH([Date]) >=7 , YEARDATE , YEARDATE - 1)
RETURN ROW (
"DAY", DayDate,
"YEAR", YEARDATE,
"MONTH NUMBER", MONTHNUMBER,
"MONTH", FORMAT ( BASEDATE, "MMMM" ),
"YEAR MONTH NUMBER", YEARMONTHNUMBER,
"YEAR MONTH", FORMAT ( BASEDATE, "MMM YY" ),
------------------------------
"Week Number",WEEKNUM([Date]),
"Week Ending",[Date] + (6-(WEEKDAY([Date],3))),
"Day Name" , FORMAT([Date],"DDDD"),
"CalendarQtr" , INT(MONTH([Date]) / 4) + 1 ,       
--
"FinancialQtr" , "FYQ" & FINANCIALQTR ,
"FinancialYr" ,"FY" & FINANCIALYR,
"FinancialYrQtr" ,  FINANCIALQTR &  FINANCIALYR             

)
)

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Hi Phil - Could you give syntax for calculating fiscal month number, if my fiscal month is starting in April?

Thanks Phil.

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

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