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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
MXXIV
Regular Visitor

How to convert a column from number to Duration in Direct Query, without switching to import mode?

I have been trying to convert a UNIX timestamp to datetime in Power Query. I am using Direct Query, not Import.

 

I am very surprised that this is so difficult. I keep getting this error:

 

This step results in a query that is not supported in DirectQuery mode

 

Of course I had to type that error in here, as it cannot be copied. Now I have been investigating and have narrowed the problem down to the duration conversion. This is my code, step by step:

 

 

let
    Source = Snowflake.Databases("XXXXXX.snowflakecomputing.com","WAREHOUSE_NAME"),
    DB_NAME_Database = Source{[Name="DB_NAME",Kind="Database"]}[Data],
    PUBLIC_Schema = DB_NAME_Database{[Name="PUBLIC",Kind="Schema"]}[Data],
    TABLENAME_View = PUBLIC_Schema{[Name="TABLENAME",Kind="View"]}[Data],
    UNIX_EPOCH = #datetime(1970, 1, 1, 0, 0, 0),
    UnixEpochColumnStep = Table.AddColumn(TABLENAME_View, "unix_epoch", each UNIX_EPOCH),
    TimestampToDays = Table.AddColumn(UnixEpochColumnStep, "timestamp_days", each [timestamp]/86400.0, Double.Type),
    //ToDurationStep = Table.AddColumn(TimestampToDays, "timestamp_as_duration", each Duration.From([timestamp_days])),
    ToDurationStep = Table.AddColumn(TimestampToDays, "timestamp_as_duration", each #duration(0,0,0,[timestamp])),
    TimestampToDateStep = Table.AddColumn(ToDurationStep, "timestamp_as_date", each [unix_epoch]),
in
    DuplicateStep

 

 

Now  by separating this into steps, I can see that the error I am getting is caused by either each Duration.From([timestamp_days]) or each #duration(0,0,0,[timestamp]). Both of these cause the error.

 

Is there a method to converting UNIX timestamp to datetime that does not need Duration and does not trigger this error?

1 ACCEPTED SOLUTION
AmiraBedh
Super User
Super User

 

You can try to convert the column from number to duration format in DirectQuery mode by using UTCDateTime and DateTimeZone  : Datetime = DateTimeZone(UTCDateTime(1970, 1, 1, 0, 0, [UnixTimestampColumn]), "UTC")


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

View solution in original post

1 REPLY 1
AmiraBedh
Super User
Super User

 

You can try to convert the column from number to duration format in DirectQuery mode by using UTCDateTime and DateTimeZone  : Datetime = DateTimeZone(UTCDateTime(1970, 1, 1, 0, 0, [UnixTimestampColumn]), "UTC")


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.