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

Get certified in Microsoft Fabric—for free! For a limited time, the Microsoft Fabric Community team will be offering free DP-600 exam vouchers. Prepare now

Reply
Likando_Luywa
New Member

CALENDAR DATES GENERATION

 

table name : AW_Fact_Sales

field NAME: OrderDate

The first orderdate is 15 – October 2001 

The last orderdate is 29 – Nov 2019.

WANT TO CREATE A DATE FIELD IN MY CALEDER TABLE USING THE ABOVE VALUES AS MY STARTDATE AND ENDDATE

The below fields are in calendar table and they are generating dates of 1900

Date5 =

CALENDAR(FIRSTDATE(AW_Fact_Sales[OrderDate].[Date]),LASTDATE(AW_Fact_Sales[OrderDate].[Date]))

DATE 2 CALENDAR(FIRSTDATE(AW_Fact_Sales[OrderDate]),LASTDATE(AW_Fact_Sales[OrderDate]))

 

Even this field below is generating dates of 1900.

date4 = CALENDAR(15/10/2001,29/11/2019)

.WHY

 

2 ACCEPTED SOLUTIONS
YukiK
Impactful Individual
Impactful Individual

You can create a calendar table using DAX code like the following:

 

Date =
VAR MinYear = YEAR ( MIN ( Sales[Order Date] ) )
VAR MaxYear = YEAR ( MAX ( Sales[Order Date] ) )
RETURN
ADDCOLUMNS (
    FILTER (
        CALENDARAUTO( ),
        AND ( YEAR ( [Date] ) >= MinYear, YEAR ( [Date] ) <= MaxYear )
    ),
    "Calendar Year", "CY " & YEAR ( [Date] ),
    "Month Name", FORMAT ( [Date], "mmmm" ),
    "Month Number", MONTH ( [Date] )
)
 

View solution in original post

Fowmy
Super User
Super User

@Likando_Luywa 

Specify the start and end date and ensure the dates table has data for the whole year. You use below code for your Dates table creation,

Dates = 
VAR StartYear = YEAR( MIN(Orders[Order Date]) )
VAR EndYear = YEAR( MAX(Orders[Order Date]) )
VAR DatesColumn = CALENDAR( DATE(StartYear , 1 , 1), DATE(EndYear, 12 , 31))
RETURN
ADDCOLUMNS(
    DatesColumn,
    "Month No" , MONTH([Date]),
    "Month Name" , FORMAT( [Date] , "Mmmm" ),
    "Year" , YEAR([Date]),
    "Month Year No" , (YEAR([Date]) * 100) + MONTH([Date]),
    "Month Year" , FORMAT( [Date] , "Mmm yyyy"),
    "Quarter" , QUARTER([Date]),
    "Qtr Name" , FORMAT( [Date] , "\QQ"),
    "Week Day" , WEEKDAY([Date],2),
    "Week" , FORMAT( [Date] , "Dddd" ),
    "Week No" , WEEKNUM([Date],2),
    "Week Num" , "WK - " & WEEKNUM([Date],2)  
)
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

3 REPLIES 3
mahoneypat
Microsoft Employee
Microsoft Employee

This article/video explains how to do this in the query editor or with DAX.  And it creates columns that do not need Sort By Columns (e.g., Month, YearMonth).

No Sort Date Tables! – Hoosier BI

 

Pat

 





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

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Fowmy
Super User
Super User

@Likando_Luywa 

Specify the start and end date and ensure the dates table has data for the whole year. You use below code for your Dates table creation,

Dates = 
VAR StartYear = YEAR( MIN(Orders[Order Date]) )
VAR EndYear = YEAR( MAX(Orders[Order Date]) )
VAR DatesColumn = CALENDAR( DATE(StartYear , 1 , 1), DATE(EndYear, 12 , 31))
RETURN
ADDCOLUMNS(
    DatesColumn,
    "Month No" , MONTH([Date]),
    "Month Name" , FORMAT( [Date] , "Mmmm" ),
    "Year" , YEAR([Date]),
    "Month Year No" , (YEAR([Date]) * 100) + MONTH([Date]),
    "Month Year" , FORMAT( [Date] , "Mmm yyyy"),
    "Quarter" , QUARTER([Date]),
    "Qtr Name" , FORMAT( [Date] , "\QQ"),
    "Week Day" , WEEKDAY([Date],2),
    "Week" , FORMAT( [Date] , "Dddd" ),
    "Week No" , WEEKNUM([Date],2),
    "Week Num" , "WK - " & WEEKNUM([Date],2)  
)
Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

YukiK
Impactful Individual
Impactful Individual

You can create a calendar table using DAX code like the following:

 

Date =
VAR MinYear = YEAR ( MIN ( Sales[Order Date] ) )
VAR MaxYear = YEAR ( MAX ( Sales[Order Date] ) )
RETURN
ADDCOLUMNS (
    FILTER (
        CALENDARAUTO( ),
        AND ( YEAR ( [Date] ) >= MinYear, YEAR ( [Date] ) <= MaxYear )
    ),
    "Calendar Year", "CY " & YEAR ( [Date] ),
    "Month Name", FORMAT ( [Date], "mmmm" ),
    "Month Number", MONTH ( [Date] )
)
 

Helpful resources

Announcements
September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

October NL Carousel

Fabric Community Update - October 2024

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