cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Canknucklehead
Helper I
Helper I

Calculated Date Column Showing Underlying Date

This is a strange issue.

 

In a Table, I have a Last Received date column. Due to a quirk in the database, this column may contain invalid dates - 0001-01-01 or 9999-12-31. These dates, of course, cause problems with visuals and date calculations. So I created a new column using this code:

Received to Stock = if([Last Received to Stock] = date(0001,01,01) || [Last Received to Stock]=date(9999,12,31),blank(), [Last Received to Stock])  In the Received to Stock column, invalid dates now simply show as blank. This is done at the Dataset level.
 
When I create a report using this dataset, something is causing this Received to Stock column to sometimes display a blank and other times to show the invalid date from the parent column and I can't understand why.
 
In Power Query in the dataset, the raw data shows here:
Canknucklehead_1-1626718254123.png
 
In the table view, the last three columns are all calculated and show correct information. Power BI doesn't display the invalid date in the Last Received to Stock column in this view - it simply shows as blank. This dashboard is to be utilized by Purchasing to allow them to track vendor performance. Being able to filter just the Open Orders is a must. Sorting On Time vs Late or Early is useful as well.
Canknucklehead_2-1626718287098.png

 

If I try and create a visual in the report using the Received to Stock column, I have three problems. 

Problem 1 - by default, it displays as Date Hierarchy. This will show a date of December 30, 1899. Changing the display to just be Recieved to Stock changes the output to a Blank. I do not understand why this column still sees the underlying invalid date information if I have set it specifically to be blank.

Problem 2 - the Blank output only displays if the PO Number column is included in the visual, and only the PO Number column. If I add in any other columns, it reverts to the December 30, 1899 display.

Problem 3 - the Later or Early and the Days Early or Late columns both change their values based on in a visual to dispaly the information as calculated based on the Dec. 30, 1899 entry. 

Canknucklehead_3-1626718829965.png

 

 Any idea what I'm doing wrong?
 
 
1 ACCEPTED SOLUTION
DataInsights
Super User II
Super User II

@Canknucklehead,

 

It's best to do transformations in SQL or Power Query. Do you have the ability to write custom SQL? If not, you could create a custom column in Power Query:

 

if List.Contains({#date(1,1,1), #date(9999,12,31)}, [Last Received to Stock]) then
  null
else
  [Last Received to Stock]

 

DataInsights_3-1626791702076.png

 

 

View solution in original post

2 REPLIES 2
Canknucklehead
Helper I
Helper I

Thank you. That appears to have fixed my issue.

DataInsights
Super User II
Super User II

@Canknucklehead,

 

It's best to do transformations in SQL or Power Query. Do you have the ability to write custom SQL? If not, you could create a custom column in Power Query:

 

if List.Contains({#date(1,1,1), #date(9999,12,31)}, [Last Received to Stock]) then
  null
else
  [Last Received to Stock]

 

DataInsights_3-1626791702076.png

 

 

View solution in original post

Helpful resources

Announcements
PBI_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Get Ready for Power BI Dev Camp

Microsoft named a Leader in The Forrester Wave

Microsoft received the highest score of any vendor in both the strategy and current offering categories.

Get Ready for Power BI Dev Camp

Power BI Dev Camp - September 30th, 2021

Mark your calendars and join us for our next Power BI Dev Camp!

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Top Solution Authors