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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
LearningStill
New Member

Help With Date Formatting

Hello,

 

I was hoping to get some help regarding changing data type for one of my columns in PowerBI to a date data type. I am using the Data view to do this. As you can see in the screen caps below, the data type before changing the column is "Whole number" and I tried changing to "Date" data type with the format as "yyyy-mm" since that is what is on the column. However, when I do this, the date changes completely and I do not know where this new date is even coming from. I tried seeing if there was a solution online but I am not sure exactly how to phrase the question without screenshots and could not find a solution which is why I created my own post. I apologize in advance if this was already posted in the past.

888fc1a8-bca4-4985-9f7d-317c46a8dba0.png

622dd54d-e6ea-447b-94cf-13df22df870b.png

Before changing data typeBefore changing data type

e8e65be8-df30-4935-b9a0-5c818a347755.png

2 REPLIES 2
vicky_
Super User
Super User

vicky__1-1680578627858.png

 

the reason that's not working is because the dates in PowerBI can't be converted in the way that you have done it. For example, if you convert the whole number 0, the date is 30/12/1899. so when you convert 202301 to a date, you're getting the date 202301 days after 1899. The formatting just changes the way the data is displayed, but it doesn't change the underlying data.

To fix this, I suggest two things - the first is to go back to the source of the raw data and provide a proper date there. PowerBI should be able to handle the date conversion if provided a data in a normal date format. If this isn't possible, you can try to convert your column using a DAX calculated column. 

We'll need to extract the year and month, then convert both to dates. Something like the following should work:

Column = 

var monthPart = RIGHT(FORMAT([month_date_yyyymm]), 2)

var yearPart = LEFT(FORMAT([month_date_yyyymm]), 4)

return DATE(yearPart, monthPart, 1)

 

this should return the 1st of each month as a date. Note: a date type requires a day, month and year. You can apply formatting to hide the date part in your actual visuals.

Arul
Super User
Super User

@LearningStill ,

As far as based on my experience we cannot convert whole number into date but you can try the below formula in new calculated column and use it in modelling.

Date = 
VAR _year = LEFT('Table (3)'[month_date_yyyymm],4)
VAR _month = RIGHT('Table (3)'[month_date_yyyymm],2)
VAR _yearMonth = _year &"-"& _month
RETURN _yearMonth

Arul_0-1680578864646.png

Thanks,

Arul





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!


LinkedIn


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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