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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
maibacherstr
Helper III
Helper III

Reformat Month Number (where January = 1) to Text Format Returning "01" instead of "1"

Hello Community, I'm comfortable in Power Query and DAX, but am returning errors when trying to convert month number to a text format while applying IF or SWITCH comparisons and adding a transformation after that. ("DAX comparison operations do not support comparing values of type Text with values of type Integer"). My error formula starts like: IF(MonthNumber < 10, then concatenate "0" and MonthNumber. This cannot be done even while I'm tangling with helper columns). 

 

The real problem to solve is in the subject line. To expand on the problem: I have a few date columns including Month Number (numerical format) which I need to convert to an alphabetized text column. The issue seems simple, which is that months January through September are single digit, meaning I need to plug in a zero before the single digit. Thus, the column will alphabetize from 01 to 12. Without this, the alphabetized column goes: 10, 11, 12, 1, 2, 3... (incorrect!).

 

I'm happy to pursue solutions in Power Query and/or DAX. Can anyone see through this problem?

 

MANY THANKS

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@maibacherstr Try:

Column = 
    VAR __MonthNumberText = MONTH([Date]) & ""
    VAR __Length = LEN(__MonthNumberText)
RETURN
    IF(__Length = 1, "0" & __MonthNumberText,__MonthNumberText)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
maibacherstr
Helper III
Helper III

Sir that was amazing! You also gained a Twitter follower. Solution accepted, have a great day.

Greg_Deckler
Super User
Super User

@maibacherstr Try:

Column = 
    VAR __MonthNumberText = MONTH([Date]) & ""
    VAR __Length = LEN(__MonthNumberText)
RETURN
    IF(__Length = 1, "0" & __MonthNumberText,__MonthNumberText)


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.