Forum Discussion
saadat_rda
3 years agoFrequent Visitor
Converting Decimal Hours to Time Format (Issue with negative values)
Hi All, I have a dataset with the time columns: Estimated Hours, Actual Hours and Remaining Hours. I am pulling my data from an SQL server and the time fields are pulling through as decimal data...
- Anonymous3 years ago
Hi saadat_rda ,
Here are the steps you can follow:
1. Create calculated column.
Flag = var _leftEST=VALUE(LEFT('Table'[Estimate Hours],2)) var _leftACT=VALUE(LEFT('Table'[Actual_Hours],2)) var _midEST=VALUE(MID('Table'[Estimate Hours],4,2)) var _midACT=VALUE(MID('Table'[Actual_Hours],4,2)) var _left= _leftEST - _leftACT var _mid= _midEST - _midACT return SWITCH( TRUE(), _left=0 && _mid<0, "-"&""&(_left+1)&":"&60 +_mid, _left >=0 && _mid>=0,_left &":"&_mid, _left >=0 && _mid<0,_left +1 &":"& 60 +_mid, _left <0 && _mid>=0, _left&":"& _mid, BLANK() )Remaining Hours = var _len= LEN('Table'[Flag]) var _left=LEFT('Table'[Flag],1) return SWITCH( TRUE(), _len=5&&_left="-","-0"&""&MID([Flag],2,4), _len=3,"0"&""&[Flag]&""&"0", _len=4,"0"&""&[Flag], [Flag] )2. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Anonymous
3 years agoNot applicable
Hi saadat_rda ,
Here are the steps you can follow:
1. Create calculated column.
Flag =
var _leftEST=VALUE(LEFT('Table'[Estimate Hours],2))
var _leftACT=VALUE(LEFT('Table'[Actual_Hours],2))
var _midEST=VALUE(MID('Table'[Estimate Hours],4,2))
var _midACT=VALUE(MID('Table'[Actual_Hours],4,2))
var _left=
_leftEST - _leftACT
var _mid=
_midEST - _midACT
return
SWITCH(
TRUE(),
_left=0 && _mid<0, "-"&""&(_left+1)&":"&60 +_mid,
_left >=0 && _mid>=0,_left &":"&_mid,
_left >=0 && _mid<0,_left +1 &":"& 60 +_mid,
_left <0 && _mid>=0, _left&":"& _mid,
BLANK()
)
Remaining Hours =
var _len=
LEN('Table'[Flag])
var _left=LEFT('Table'[Flag],1)
return
SWITCH(
TRUE(),
_len=5&&_left="-","-0"&""&MID([Flag],2,4),
_len=3,"0"&""&[Flag]&""&"0",
_len=4,"0"&""&[Flag],
[Flag]
)
2. Result:
Best Regards,
Liu Yang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
- saadat_rda3 years agoFrequent Visitor
Thanks Liu. It worked and I really appreciate this!