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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
hale
Helper II
Helper II

Error when passing datetime to SQL server table function that is expecting smalldatetime type

Hi,

 

I am trying to call a table function in our SQL database and it is expecting smalldatetime but Power Query Editor always return this error:
DataSource.Error: Microsoft SQL: The conversion of a datetime2 data type to a smalldatetime data type resulted in an out-of-range value.
Details:
DataSourceKind=SQL
DataSourcePath=******
Message=The conversion of a datetime2 data type to a smalldatetime data type resulted in an out-of-range value.
ErrorCode=-2146232060
Number=242
Class=16


Below is my attempt (sensitive data is masked with XXXX):

 

let
    Source = Sql.Database(XXXX, XXXXXX),
    dbo_Report = Source{[Schema="dbo",Item="Report"]}[Data],
    
    #"Invoked Function" = dbo_Report(XXXXX, #datetime(2000,1,1,0,0,0) , #datetime(2080,1,1,0,0,0))

in
    #"Invoked Function"

 

 

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @hale 

 

It is because the value #datetime(2080,1,1,0,0,0) you passed in the function is out of the range of smalldatetime type. I guess the column in your SQL Server table is set to smalldatetime type, so it cannot accept this value, which leading to this error.

 

Please refer to this official doc:smalldatetime (Transact-SQL) - SQL Server

vjingzhang_0-1664331748714.png

 

Date & time data type value range

Data type Date & Time Range
datetime 1753-01-01 00:00:00 ~ 9999-12-31 23:59:59.997
datetime2 0001-01-01 00:00:00 ~ 9999-12-31 23:59:59.9999999
date 0001-01-01 ~ 9999-12-31
smalldatetime 1900-01-01 00:00:00 ~ 2079-06-06 23:59:59

 

To resolve it, please pass a smaller value than #datetime(2079,6,6,23,59,59), or change the column data type to datetime or datetime2 type in your SQL Server table.

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
 

View solution in original post

4 REPLIES 4
v-jingzhang
Community Support
Community Support

Hi @hale 

 

It is because the value #datetime(2080,1,1,0,0,0) you passed in the function is out of the range of smalldatetime type. I guess the column in your SQL Server table is set to smalldatetime type, so it cannot accept this value, which leading to this error.

 

Please refer to this official doc:smalldatetime (Transact-SQL) - SQL Server

vjingzhang_0-1664331748714.png

 

Date & time data type value range

Data type Date & Time Range
datetime 1753-01-01 00:00:00 ~ 9999-12-31 23:59:59.997
datetime2 0001-01-01 00:00:00 ~ 9999-12-31 23:59:59.9999999
date 0001-01-01 ~ 9999-12-31
smalldatetime 1900-01-01 00:00:00 ~ 2079-06-06 23:59:59

 

To resolve it, please pass a smaller value than #datetime(2079,6,6,23,59,59), or change the column data type to datetime or datetime2 type in your SQL Server table.

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
 

Hi Jing,

 

That's exactly the issue. However I dont have any control over SQL database so Im looking for something I can do from Power BI side.
Is there anything else that I can try?

Hi @hale 

 

Is this function used to filter rows between those two dates? If the column doesn't hold date values after 2079-06-06 in the SQL table, you can pass an earlier date in the function. Is this possible to solve it?

 

Best Regards,
Community Support Team _ Jing

oh thanks, it actually is working. The 2 parameters I can pass in like this and it works:

#datetime(2000,1,1,1,1,1) , #datetime(2022,1,5,1,1,1)

Cheers,

Ha Le

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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