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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Rosepowerbi
New Member

Change whole number to a date

I have a period 202201 which is formatted as a whole number.

 

I want to add a custom column which is in a date format and looks like Jan 22

 

Please help!

 

Thanks

Rose

1 ACCEPTED SOLUTION
AmiraBedh
Resident Rockstar
Resident Rockstar

Hi again, last time I didn't pay attention to your input, I tried to reproduce it using Power Query like below :

 

= Table.AddColumn(#"Renamed Columns", "Custom", each
if Text.End([Period], 2) = "01" then "Jan" & " " & Text.Middle([Period], 2, 2)
else if Text.End([Period], 2)= "02" then "Feb" & " " & Text.Middle([Period], 2, 2)
else if Text.End([Period], 2) = "03" then "Mar" & " " & Text.Middle([Period], 2, 2)
else if Text.End([Period], 2) = "04" then "Apr" & " " & Text.Middle([Period], 2, 2)

else ....
else "")

 

AmiraBedh_0-1677349646259.png

 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

View solution in original post

7 REPLIES 7
AmiraBedh
Resident Rockstar
Resident Rockstar

Hi again, last time I didn't pay attention to your input, I tried to reproduce it using Power Query like below :

 

= Table.AddColumn(#"Renamed Columns", "Custom", each
if Text.End([Period], 2) = "01" then "Jan" & " " & Text.Middle([Period], 2, 2)
else if Text.End([Period], 2)= "02" then "Feb" & " " & Text.Middle([Period], 2, 2)
else if Text.End([Period], 2) = "03" then "Mar" & " " & Text.Middle([Period], 2, 2)
else if Text.End([Period], 2) = "04" then "Apr" & " " & Text.Middle([Period], 2, 2)

else ....
else "")

 

AmiraBedh_0-1677349646259.png

 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

For example: your date column came in this numeric format....20141002......YYYYMMDD

 

You can convert it to the date type without generating errors by following these steps.

 

1. Highlight the column

2. Right click on the highlighted column and select "Change Type."

3. Select "Text"

4. Right click on the highlighted column again and select "Change Type."

6. Select "Date"

7. There'll be a pop up showing "Change Column Type", Select "Add new step.

8. Then you have the date type without errors.

(2014/10/02)

I hope this helps 🙏

Hi thanks but I'm still getting an error, my period is a whole number format, not text

I need 'Jan 22' to be a date format

thanks

Rose

Rosepowerbi
New Member

thanks for your quick response

I got an error when I tried the first bit

What is the error message that you get ?

I already tried it using DAX : 

AmiraBedh_0-1677068152284.png

 

and in Power Query : 

AmiraBedh_1-1677068647596.png

 


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

I tried to add a custom column in power query with your formula NewColumnDate.FromText(Text.From([Period], "0000-00"))

 

It just says error in all the rows of the table, I didn't get a specific error message

 

Rosepowerbi_0-1677068954917.png

 

 

AmiraBedh
Resident Rockstar
Resident Rockstar

In Power Query : NewColumn= Date.FromText(Text.From([Period], "0000-00"))

In DAX : MonthYear = FORMAT(DATE(LEFT('Table'[Period],4),RIGHT('Table'[Period],2),1),"mmm yy")


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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