Forum Discussion
Hours Conversion
- Anonymous1 year ago
Hi uie07923 ,
What type is the Hours column after it is imported into Power BI? If it is text type, you can consider the following method.
According to your description, only the negative value are not converted. You can use IF to judge whether the hour of the current row is negative, if yes then convert it.
Here is my test for your reference.
Calculated column.
_hours = VAR _tag = CONTAINSSTRING('Table'[TimeOfHous],":") VAR _hour = LEFT('Table'[TimeOfHous], SEARCH(":", 'Table'[TimeOfHous]) - 1) VAR _minute = MID('Table'[TimeOfHous], SEARCH(":", 'Table'[TimeOfHous]) + 1, SEARCH("-", 'Table'[TimeOfHous]) - SEARCH(":", 'Table'[TimeOfHous]) - 1) RETURN IF(_tag,"-"&SUBSTITUTE(CONVERT((VALUE(_hour)+VALUE(_minute)/60)/24,STRING),".",","),'Table'[TimeOfHous])——————————————————————————————————————————————————
If my answer helps you solve the problem, please accept my answer as a solution and let it be seen by more people in need.
Best regards,
Mengmeng Li
Hi uie07923 ,
What type is the Hours column after it is imported into Power BI? If it is text type, you can consider the following method.
According to your description, only the negative value are not converted. You can use IF to judge whether the hour of the current row is negative, if yes then convert it.
Here is my test for your reference.
Calculated column.
_hours =
VAR _tag = CONTAINSSTRING('Table'[TimeOfHous],":")
VAR _hour = LEFT('Table'[TimeOfHous], SEARCH(":", 'Table'[TimeOfHous]) - 1)
VAR _minute = MID('Table'[TimeOfHous], SEARCH(":", 'Table'[TimeOfHous]) + 1, SEARCH("-", 'Table'[TimeOfHous]) - SEARCH(":", 'Table'[TimeOfHous]) - 1)
RETURN
IF(_tag,"-"&SUBSTITUTE(CONVERT((VALUE(_hour)+VALUE(_minute)/60)/24,STRING),".",","),'Table'[TimeOfHous])
——————————————————————————————————————————————————
If my answer helps you solve the problem, please accept my answer as a solution and let it be seen by more people in need.
Best regards,
Mengmeng Li