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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
AvPowerBI
Post Patron
Post Patron

Include 0 for month number where applicable

Hi,

 

I currently have the below calendar.

 

Dates = 
    VAR MinYear = YEAR ( MIN ('Fact'[Employment Start Date] ) )
    VAR MaxYear = YEAR ( MAX ('Fact'[Employment End Date] ) )
    RETURN
    ADDCOLUMNS (
        FILTER (
            CALENDARAUTO( ),
            AND ( YEAR ( [Date] ) >= MinYear, YEAR ( [Date] ) <= MaxYear )
    ),
        "Year", FORMAT([Date], "yyyy"),
        "Date2",FORMAT( [Date], "dd/mm/yyyy" ),
        --"Calendat Year", "CY " & YEAR ( [Date] ),
        "Month Name", FORMAT ( [Date], "mmm" ),
        "Month Number", MONTH ( [Date] ),
        "Weekday", FORMAT ( [Date], "dddd" ),
        "Weekday number", WEEKDAY( [Date] ),
        "Year Month", FORMAT ( [Date], "mmm yy"),
        "Month-Year", FORMAT ( [Date], "mmm-yyyy"),
         "Month-Year 2", FORMAT ( [Date], "mmm,yy"),
         "Quarter", "Q" & TRUNC ( ( MONTH ( [Date] ) - 1 ) / 3 ) + 1
        )

 

The column  "Month Number", MONTH ( [Date] ), is show the months between January to September as a single number i.e 1 to 9

I require a zero in front so it shows as 01, 02, 03 etc.. 

I tried to add a calculated column but it shows up as an Error on the result set

 

Month =
IF(
LEN(Dates[Month Number])=1, "0" & Dates[Month Number], Dates[Month Number]
)
 
and then once I have the calculated column Month created I then wanted to create another calculated column that has a date for start of the month like this one 
 
Start of Month = "01-" & Dates[Month] & "-" & Dates[Year]
 
But this will not work because the Month column is currently showing #ERROR
 
AvPowerBI_0-1643965968240.png

 

Thanks

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@AvPowerBI , try like

format(MONTH ( [Date] ), "00")

View solution in original post

2 REPLIES 2
v-zhangti
Community Support
Community Support

Hi, @AvPowerBI 

 

You can check the following methods.

Month = FORMAT(MONTH(Dates[Date]),"00")
Start of Month = "01-"&[Month]&"-"&[Year]

vzhangti_0-1644473573864.png

More information about time and date formats can be found in the following links.

https://docs.microsoft.com/dax/format-function-dax 

 

Best Regards,

Community Support Team _Charlotte

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

amitchandak
Super User
Super User

@AvPowerBI , try like

format(MONTH ( [Date] ), "00")

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.