Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
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"
Solved! Go to Solution.
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
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 @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
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
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 5 | |
| 3 | |
| 3 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 9 | |
| 8 | |
| 7 | |
| 7 | |
| 5 |