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
admin_xlsior
Post Prodigy
Post Prodigy

Direct Query : Transform Integer Value to Time datatype and time format

Hi,

 

I have a fact table which coming from Direct Query, in which it supposed to be an integer contain second (time)

 

Sample as below: (the 1st 2 column is the original value from SQL table, and the rest is just after SQL function Convert which I'm using for checking :

STARTTIMESTOPTIMESTARTTIMESTOPTIME
85105023:38:250:00:00
85105023:38:250:00:00
85105023:38:250:00:00
000:00:000:00:00
000:00:000:00:00
000:00:000:00:00
000:00:000:00:00
000:00:000:00:00
000:00:000:00:00
668306697318:33:5018:36:13
66830018:33:500:00:00
668306697318:33:5018:36:13
670206720018:37:0018:40:00
67020018:37:000:00:00
683296834218:58:4918:59:02
68329018:58:490:00:00
683296834218:58:4918:59:02
670206720018:37:0018:40:00

 

The way I import is not with the last 2 column, so it is just the 1st 2 column, the integer value to Power BI. And in Edit Query, when I change the Data type to Time, it give me error.

 

The last 2 column is the way I want Power BI to display.

 

Please help,

 

Thanks,

 

 

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @admin_xlsior ,

 

You can use following calculate column to achieve your requirement:

STOPTIME = 
var _hour=INT([STOPTIME]/3600)
var _minute=MOD([STOPTIME],3600)/60
var _second=MOD(MOD([STOPTIME],3600),60)
return
TIME(_hour,_minute,_second)

STARTTIME = 
var _hour=INT([STARTTIME]/3600)
var _minute=MOD([STARTTIME],3600)/60
var _second=MOD(MOD([STARTTIME],3600),60)
return
TIME(_hour,_minute,_second)

Notice: above formula not works on value who greater than 24 hours.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

1 REPLY 1
v-shex-msft
Community Support
Community Support

Hi @admin_xlsior ,

 

You can use following calculate column to achieve your requirement:

STOPTIME = 
var _hour=INT([STOPTIME]/3600)
var _minute=MOD([STOPTIME],3600)/60
var _second=MOD(MOD([STOPTIME],3600),60)
return
TIME(_hour,_minute,_second)

STARTTIME = 
var _hour=INT([STARTTIME]/3600)
var _minute=MOD([STARTTIME],3600)/60
var _second=MOD(MOD([STARTTIME],3600),60)
return
TIME(_hour,_minute,_second)

Notice: above formula not works on value who greater than 24 hours.

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

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.