Add leading 0 (zero) to month number in power BI

StackTrace picture StackTrace · Oct 31, 2018 · Viewed 8k times · Source

I have the below DAX formula that is concatenating a month number to a year.
If the month number is less than 10, i want to add a leading zero to it but i'm new to DAX and i can't seem to figure out how to do it.

Expiry_MonthYear_Sorter = [Expiry_Date].[Year]  & [Expiry_Date].[MonthNo]

As an example, if the year is 2018 and the month number is 2, i want the value to be 201802.

Currently, my formula gives me 20182

Answer

Alexis Olson picture Alexis Olson · Oct 31, 2018

You can use the FORMAT function for this.

Expiry_MonthYear_Sorter = FORMAT([Expiry_Date], "YYYYMM")