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
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
Employee
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
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.