cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
granthworth Regular Visitor
Regular Visitor

DAX issue with Date data type

I am having an issue today with a DAX formula.

 

The scenario is as follows. I have 2 Power BI desktop files which are formatted identically. I have them linked to separate Excel workbooks which are formatted identically. I am inserting a calculated column into both datasets under "Modeling" in Power BI with the following formula:

 

Week_Crctd = if(weeknum('Line Calls'[Date])<=52,(weeknum('Line Calls'[Date])),1)

In one PBI desktop file, I receive the expected result; a whole number between 1 and 52 which varies correctly according to the [Date] value. In the other file, I receive the following error:

 

Error.png

 

As I mentioned before, both Excel files are formatted with the exact same number formatting in these columns and both PBI desktop files are formatted with the same Data Type, Format, Data Category, and Default Summarization. What gives?

 

Thanks guys and gals

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
granthworth Regular Visitor
Regular Visitor

Re: DAX issue with Date data type

Thanks for the input everyone.

 

However, after going through my source data, I found the following string of typos in the date column. Correcting them also corrected this issue.

 

381	1/19/16
382	1/19/16
383	1/19/16
384	1/19/16
385	1/19/16
386	1/19/16
387	01/119
388	01/119
389	01/119
390	01/119

I have adjusted the data validation and formatting restrictions to the user form through which this data is input.

 

Thanks again for helping with my case of the Mondays.

 

View solution in original post

5 REPLIES 5
Super User
Super User

Re: DAX issue with Date data type

I'm guessing that in your second sheet that your [Date] column is not tagged as a datetime type, but rather a text type. Could be a regional issue where months and days are flipped.

I have book! Learn Power BI from Packt


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

Proud to be a Datanaut!

greggyb New Contributor
New Contributor

Re: DAX issue with Date data type

That's a real zinger.

 

It took me a little while to reproduce. I can reliably get that behavior for any date < 1899-12-30. That is the 0-date in the Tabular engine, and my guess is that someone didn't handle negative values appropriately in the function definition. I can bounce up against the upper date boundary without errors.

 

Do you have data with dates < 1899-12-30?

 

**Edit:**

Power Query does not suffer from a similar error, and Date.WeekOfYear() is functional in the full range from 0001-01-01 through 9999-12-31. DAX Can't handle dates as small as 0001-01-01, so you should be good to do this sort of transformation in Power Query. Generally it's a better practice to do transformations before importing to the data model, anyway, to take advantage of better compression.

 

**Edit2:**

The error reported in the original post seems to be unique to <1899-12-30 dates. If I input malformed dates or text strings I get

Cannot convert value '4' of type Text to type Date.
Super User
Super User

Re: DAX issue with Date data type

Huh, if it is a pre-1900 date issue, I guess I should have thought of that, I just posted an article on it in the Community Blog! 🙂

I have book! Learn Power BI from Packt


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

Proud to be a Datanaut!

greggyb New Contributor
New Contributor

Re: DAX issue with Date data type

@Greg_Deckler, the 0-date in Tabular is 1899-12-30, not 1900-01-01. This is actually inconsistent with both Excel and SQL Server.

 

As you can see below, I've created a table with the integer values -1, 0, and 1. I then change the data type to Date, and I get back 1899-12-29, 1899-12-30, and 1899-12-31. The misbehavior starts for anything with a negative offset from the 0-date.

 

Capture.JPGFirst integersCapture-1.JPGIntegers converted to Date datatype in PBI

Highlighted
granthworth Regular Visitor
Regular Visitor

Re: DAX issue with Date data type

Thanks for the input everyone.

 

However, after going through my source data, I found the following string of typos in the date column. Correcting them also corrected this issue.

 

381	1/19/16
382	1/19/16
383	1/19/16
384	1/19/16
385	1/19/16
386	1/19/16
387	01/119
388	01/119
389	01/119
390	01/119

I have adjusted the data validation and formatting restrictions to the user form through which this data is input.

 

Thanks again for helping with my case of the Mondays.

 

View solution in original post

Helpful resources

Announcements
Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

October 2019 Community Highlights

October 2019 Community Highlights

October was a busy month in the community. Read the recap article to learn about some of the events and content.

New Solution Badges

New Solution Badges

Two waves of brand new solution badges are coming! Read the article for more information on our new community badges.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Users Online
Currently online: 45 members 937 guests
Please welcome our newest community members: