Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

powerbi

dax

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

like image 612
StackTrace Avatar asked Dec 11 '22 04:12

StackTrace


1 Answers

You can use the FORMAT function for this.

Expiry_MonthYear_Sorter = FORMAT([Expiry_Date], "YYYYMM")
like image 179
Alexis Olson Avatar answered Feb 27 '23 20:02

Alexis Olson