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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
granthworth
Helper II
Helper II

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

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
greggyb
Resident Rockstar
Resident Rockstar

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.

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.

 

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! 🙂

@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

@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.

 

First integersFirst integersIntegers converted to Date datatype in PBIIntegers converted to Date datatype in PBI

Greg_Deckler
Super User
Super User

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.

@ 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!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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