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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Expression.Error: The number is out of range of a 32 bit integer value. Convert an Number to a Date

Hi there.  

 

Our SQL guys land dates in the form of text.  They use the following SQL script to generate the date.

 

SELECT

Termination_order_final_termination_date

,DATEADD(SS,CAST(SUBSTRING(CAST([Termination_order_final_termination_date] AS VARCHAR),1,10) AS BIGINT),'19700101') as Termination_order_final_termination_date_converted

From [LANDING].[LND_QBS_RAT_Replacement_Orders]

 

I converted the the text string to a date in Power Query by using the following M Script:  

 

"Date", each if [Termination_order_final_termination_date] = "" then null else Date.AddDays(#date(1970,01,01),Number.FromText(Text.Start([Termination_order_final_termination_date],10))/86400))

 

Most of them convert correct except the negative Dates.  I tried Number.Abs, however that does not work.

 

SamanthaP84_3-1655011739950.png

 

In the SQL script they do not result in Errors.  Please can someone Help me.

 

SamanthaP84_2-1655011510086.png

I think it is something to do with the BIGINT thing.

 

 

1 ACCEPTED SOLUTION
Vijay_A_Verma
Super User
Super User

Actually Date.AddDays expects an integer number. If you want date only, then following should be there for Date.AddDays

Date.AddDays(#date(1970,01,01),Number.IntegerDivide(Number.FromText(Text.Start([Termination_order_final_termination_date],10))/86400,1))

One more point is that when you extract 10 length from negative number, it will have minus sign + 9 digits....So, if you want to extract 10 digits from negative numbers also, then you will need to adjust your formula appropriately.

View solution in original post

2 REPLIES 2
Vijay_A_Verma
Super User
Super User

Actually Date.AddDays expects an integer number. If you want date only, then following should be there for Date.AddDays

Date.AddDays(#date(1970,01,01),Number.IntegerDivide(Number.FromText(Text.Start([Termination_order_final_termination_date],10))/86400,1))

One more point is that when you extract 10 length from negative number, it will have minus sign + 9 digits....So, if you want to extract 10 digits from negative numbers also, then you will need to adjust your formula appropriately.

ImkeF
Community Champion
Community Champion

Hi @Anonymous ,
in the Date.AddDays-function, the number must be a whole number. So if you round it, you will get a date.
But if you want to keep the DateTime part of it as well, you can convert first convert the date to number and then use a plus sign to calculate the new datetime:

DateTime.From( Number.From( #date(1970,01,01)) + ,Number.FromText(Text.Start([Termination_order_final_termination_date],10))/86400))

 

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
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Top Solution Authors