cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Jack2of3 Frequent Visitor
Frequent Visitor

Add a leading 0 (zero) in a DAX FORMAT([Date], "yy") formula

HI all, I've created a CALENDAR and can get everything functioning normally except when incrementing the "YY" by +1 in the following formula.

"FisPerName", UPPER(FORMAT([Date],"MMM")) & "-" &
SWITCH(TRUE(),Month([Date])<7,FORMAT([Date], "yy"),FORMAT([Date], "yy"))+1.
 
I expect it to be:
AUG-07 but get AUG-7....
 
CONCATENATING a 0 before the format doesn't work when the year is 10 or higher. Gives 010, 011, etc.
 
This is all the code:
DateTable = ADDCOLUMNS (
CALENDAR (DATE(2000,07,01), DATE(2035,06,30)),"Day of Month",DAY([Date]),
"Day",FORMAT([Date],"DDDD"),
"Year", FORMAT([Date],"YYYY"),
"Month", FORMAT([Date],"MMMM"),
    "Period", Month([Date]),
    "PerName", UPPER(FORMAT([Date],"MMM")) & "-" & FORMAT([Date], "yy"),
"Quarter", SWITCH( MONTH([Date]),
1, "Qtr1",
2, "Qtr1",
3, "Qtr1",
4, "Qtr2",
5, "Qtr2",
6, "Qtr2",
7, "Qtr3",
8, "Qtr3",
9, "Qtr3",
10, "Qtr4",
11, "Qtr4",
"Qtr4" ),
"FisYear", SWITCH(TRUE(),Month([Date])<7,YEAR([Date]),YEAR([Date])+1),
"FisQtr", SWITCH( MONTH([Date]),
1, "Qtr3",
2, "Qtr3",
3, "Qtr3",
4, "Qtr4",
5, "Qtr4",
6, "Qtr4",
7, "Qtr1",
8, "Qtr1",
9, "Qtr1",
10, "Qtr2",
11, "Qtr2",
"Qtr2" ),
"FisPer", SWITCH(TRUE(),Month([Date])<7,Month([Date])+6,Month([Date])-6),
    "FisPerName", UPPER(FORMAT([Date],"MMM")) & "-" & SWITCH(TRUE(),Month([Date])<7,FORMAT([Date], "yy"),FORMAT([Date], "yy"))+1)
1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Add a leading 0 (zero) in a DAX FORMAT([Date], "yy") formula

Hi @Jack2of3 ,

 

To update your formula as below.

 

DateTable =
ADDCOLUMNS (
    CALENDAR ( DATE ( 2000, 07, 01 ), DATE ( 2035, 06, 30 ) ),
    "Day of Month", DAY ( [Date] ),
    "Day", FORMAT ( [Date], "DDDD" ),
    "Year", FORMAT ( [Date], "YYYY" ),
    "Month", FORMAT ( [Date], "MMMM" ),
    "Period", MONTH ( [Date] ),
    "PerName", UPPER ( FORMAT ( [Date], "MMM" ) ) & "-"
        & FORMAT ( [Date], "yy" ),
    "Quarter", SWITCH (
        MONTH ( [Date] ),
        1, "Qtr1",
        2, "Qtr1",
        3, "Qtr1",
        4, "Qtr2",
        5, "Qtr2",
        6, "Qtr2",
        7, "Qtr3",
        8, "Qtr3",
        9, "Qtr3",
        10, "Qtr4",
        11, "Qtr4",
        "Qtr4"
    ),
    "FisYear", SWITCH ( TRUE (), MONTH ( [Date] ) < 7, YEAR ( [Date] ), YEAR ( [Date] ) + 1 ),
    "FisQtr", SWITCH (
        MONTH ( [Date] ),
        1, "Qtr3",
        2, "Qtr3",
        3, "Qtr3",
        4, "Qtr4",
        5, "Qtr4",
        6, "Qtr4",
        7, "Qtr1",
        8, "Qtr1",
        9, "Qtr1",
        10, "Qtr2",
        11, "Qtr2",
        "Qtr2"
    ),
    "FisPer", SWITCH (
        TRUE (),
        MONTH ( [Date] ) < 7, MONTH ( [Date] ) + 6,
        MONTH ( [Date] ) - 6
    ),
    "FisPerName", UPPER ( FORMAT ( [Date], "MMM" ) ) & "-"
        & IF (
            SWITCH (
                TRUE (),
                MONTH ( [Date] ) < 7, FORMAT ( [Date], "yy" ),
                FORMAT ( [Date], "yy" )
            ) + 1 >= 10,
            SWITCH (
                TRUE (),
                MONTH ( [Date] ) < 7, FORMAT ( [Date], "yy" ),
                FORMAT ( [Date], "yy" )
            ) + 1,
            0
                & SWITCH (
                    TRUE (),
                    MONTH ( [Date] ) < 7, FORMAT ( [Date], "yy" ),
                    FORMAT ( [Date], "yy" )
                ) + 1
        )
)
Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Community Support Team
Community Support Team

Re: Add a leading 0 (zero) in a DAX FORMAT([Date], "yy") formula

Hi @Jack2of3 ,

 

To update your formula as below.

 

DateTable =
ADDCOLUMNS (
    CALENDAR ( DATE ( 2000, 07, 01 ), DATE ( 2035, 06, 30 ) ),
    "Day of Month", DAY ( [Date] ),
    "Day", FORMAT ( [Date], "DDDD" ),
    "Year", FORMAT ( [Date], "YYYY" ),
    "Month", FORMAT ( [Date], "MMMM" ),
    "Period", MONTH ( [Date] ),
    "PerName", UPPER ( FORMAT ( [Date], "MMM" ) ) & "-"
        & FORMAT ( [Date], "yy" ),
    "Quarter", SWITCH (
        MONTH ( [Date] ),
        1, "Qtr1",
        2, "Qtr1",
        3, "Qtr1",
        4, "Qtr2",
        5, "Qtr2",
        6, "Qtr2",
        7, "Qtr3",
        8, "Qtr3",
        9, "Qtr3",
        10, "Qtr4",
        11, "Qtr4",
        "Qtr4"
    ),
    "FisYear", SWITCH ( TRUE (), MONTH ( [Date] ) < 7, YEAR ( [Date] ), YEAR ( [Date] ) + 1 ),
    "FisQtr", SWITCH (
        MONTH ( [Date] ),
        1, "Qtr3",
        2, "Qtr3",
        3, "Qtr3",
        4, "Qtr4",
        5, "Qtr4",
        6, "Qtr4",
        7, "Qtr1",
        8, "Qtr1",
        9, "Qtr1",
        10, "Qtr2",
        11, "Qtr2",
        "Qtr2"
    ),
    "FisPer", SWITCH (
        TRUE (),
        MONTH ( [Date] ) < 7, MONTH ( [Date] ) + 6,
        MONTH ( [Date] ) - 6
    ),
    "FisPerName", UPPER ( FORMAT ( [Date], "MMM" ) ) & "-"
        & IF (
            SWITCH (
                TRUE (),
                MONTH ( [Date] ) < 7, FORMAT ( [Date], "yy" ),
                FORMAT ( [Date], "yy" )
            ) + 1 >= 10,
            SWITCH (
                TRUE (),
                MONTH ( [Date] ) < 7, FORMAT ( [Date], "yy" ),
                FORMAT ( [Date], "yy" )
            ) + 1,
            0
                & SWITCH (
                    TRUE (),
                    MONTH ( [Date] ) < 7, FORMAT ( [Date], "yy" ),
                    FORMAT ( [Date], "yy" )
                ) + 1
        )
)
Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Jack2of3 Frequent Visitor
Frequent Visitor

Re: Add a leading 0 (zero) in a DAX FORMAT([Date], "yy") formula

Thank you very much. I was banging my head trying to figure that out.

Helpful resources

Announcements
October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Badges

Incoming: New and Improved Badges

Exciting news: We've given our badges an overhaul and added brand news ones.

Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Users Online
Currently online: 228 members 2,372 guests
Please welcome our newest community members: