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
michellepace
Resolver III
Resolver III

Connection Error - how to elegantly handle dirty dates in a DATE column?

Hello,

I am connecting to a Pervasive SQL database. When trying to connect to the SupplierMaster table I am getting the below date/time error in PowerBi. This is due to the "dirty" value I have in the LastCrDate date column, namely "11/30/0011".

Question: What is the most elegant way to handle this "dirty date" scenario? (I'm not permitted to "fix" any values in the database)

 

Error & Raw Data.png

Thanks in advance, Michelle

1 ACCEPTED SOLUTION

Hi @ImkeF .
>can you copy and paste the code that has been generated for this query? 
It cannot be the code because once I fix the data in the datacase, everything works as it such. Thus ruling out the code. Nonethless, so you can see here it is: = Odbc.Query("dsn=PastelDB.odbc", "select LastCrDate from SupplierMaster")

 

Hi @v-eachen-msft ,
> Try to add a sql query with FORMAT() and import data as text.
Thank-you, this is a perfect answer!  I changed my query to = Odbc.Query("dsn=PastelDB.odbc", "select convert(LastCrDate,SQL_VARCHAR) from SupplierMaster") . It works like a charm. Now I can handle what to do with dirty dates within Power Bi (eg convert a dirty date to 01/01/1970). I'll defintely use this in future scenarios where I cannot change the db. 

 

My Final Solution: The database owner gave me permission to "fix" dirty date values in his PastelDb. So I fixed them all with this by running the below sql against the pervasive database. Power Bi works fine now with the orginal purple query above. 

 

 

update "SupplierMaster"
set LastCrDate = '1970-01-01'
WHERE LastCrDate not between '1970-01-01' and '2020-07-29'

 

Thank you both, I learnt something very useful in spite of the final solution.
Michelle

View solution in original post

5 REPLIES 5
v-eachen-msft
Community Support
Community Support

Hi @michellepace ,

 

Try to add a sql query with FORMAT() and import data as text. 

 

Community Support Team _ Eads
If this post helps, then please consider Accept it as the solution to help the other members find it.

Hi @ImkeF .
>can you copy and paste the code that has been generated for this query? 
It cannot be the code because once I fix the data in the datacase, everything works as it such. Thus ruling out the code. Nonethless, so you can see here it is: = Odbc.Query("dsn=PastelDB.odbc", "select LastCrDate from SupplierMaster")

 

Hi @v-eachen-msft ,
> Try to add a sql query with FORMAT() and import data as text.
Thank-you, this is a perfect answer!  I changed my query to = Odbc.Query("dsn=PastelDB.odbc", "select convert(LastCrDate,SQL_VARCHAR) from SupplierMaster") . It works like a charm. Now I can handle what to do with dirty dates within Power Bi (eg convert a dirty date to 01/01/1970). I'll defintely use this in future scenarios where I cannot change the db. 

 

My Final Solution: The database owner gave me permission to "fix" dirty date values in his PastelDb. So I fixed them all with this by running the below sql against the pervasive database. Power Bi works fine now with the orginal purple query above. 

 

 

update "SupplierMaster"
set LastCrDate = '1970-01-01'
WHERE LastCrDate not between '1970-01-01' and '2020-07-29'

 

Thank you both, I learnt something very useful in spite of the final solution.
Michelle

ImkeF
Super User
Super User

Hi @michellepace ,

try disabling the automatic type detection in the options:

 

image.png

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

Hi @ImkeF  thank you for your speedy reply and effort to make such an easily understantable screenshot. I tried as you suggested however I have the same error as originally posted. 🙁

Hi @michellepace ,

can you copy and paste the code that has been generated for this query? (Delete any private data of the actuals datasource, but keep all M-function in please)

 

Imke Feldmann (The BIccountant)

If you liked my solution, please give it a thumbs up. And if I did answer your question, please mark this post as a solution. Thanks!

How to integrate M-code into your solution -- How to get your questions answered quickly -- How to provide sample data -- Check out more PBI- learning resources here -- Performance Tipps for M-queries

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.

Top Solution Authors
Top Kudoed Authors