<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Converting Decimal Hours to Time Format (Issue with negative values) in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Converting-Decimal-Hours-to-Time-Format-Issue-with-negative/m-p/2906053#M94818</link>
    <description>&lt;P&gt;Hi&amp;nbsp; &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="444265" data-lia-user-login="saadat_rda" class="lia-mention lia-mention-user"&gt;saadat_rda&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are the steps you can follow：&lt;/P&gt;
&lt;P&gt;1. Create calculated column.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;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 &amp;amp;&amp;amp; _mid&amp;lt;0, "-"&amp;amp;""&amp;amp;(_left+1)&amp;amp;":"&amp;amp;60 +_mid,
_left &amp;gt;=0 &amp;amp;&amp;amp; _mid&amp;gt;=0,_left &amp;amp;":"&amp;amp;_mid,
_left &amp;gt;=0 &amp;amp;&amp;amp; _mid&amp;lt;0,_left +1 &amp;amp;":"&amp;amp; 60 +_mid,
_left &amp;lt;0 &amp;amp;&amp;amp; _mid&amp;gt;=0, _left&amp;amp;":"&amp;amp; _mid,
BLANK()
)

&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Remaining Hours =
var _len=
LEN('Table'[Flag])
var _left=LEFT('Table'[Flag],1)
return
SWITCH(
    TRUE(),
        _len=5&amp;amp;&amp;amp;_left="-","-0"&amp;amp;""&amp;amp;MID([Flag],2,4),
    _len=3,"0"&amp;amp;""&amp;amp;[Flag]&amp;amp;""&amp;amp;"0",
    _len=4,"0"&amp;amp;""&amp;amp;[Flag],
    [Flag]
    )

&lt;/LI-CODE&gt;
&lt;P&gt;2. Result:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Liu Yang&lt;/P&gt;
&lt;P&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;EM&gt;Accept it as the solution&lt;/EM&gt; to help the other members find it more quickly&lt;/P&gt;</description>
    <pubDate>Tue, 15 Nov 2022 09:40:38 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2022-11-15T09:40:38Z</dc:date>
    <item>
      <title>Converting Decimal Hours to Time Format (Issue with negative values)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Converting-Decimal-Hours-to-Time-Format-Issue-with-negative/m-p/2902889#M94600</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P class="lia-align-justify"&gt;I have a dataset with the time columns: Estimated Hours, Actual Hours and Remaining Hours.&lt;/P&gt;&lt;P class="lia-align-justify"&gt;I am pulling my data from an SQL server and the time fields are pulling through as decimal data types. So time of 45 minutes is actually showing as 0.75 hours.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm aware that there have been similar questions in this forum and the solution that I got from them was:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actual Hours = VAR total_time = SELECTEDVALUE('Table'[ActualHours])&lt;BR /&gt;VAR hrs = INT(total_time)&lt;BR /&gt;VAR mins = (total_time - hrs) * 60&lt;BR /&gt;RETURN&lt;BR /&gt;FORMAT( hrs, "00") &amp;amp; ":" &amp;amp; FORMAT(mins,"00")&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This has worked for the columns Estimated Hours and Actual Hours as they are never negative values.&lt;/P&gt;&lt;P&gt;However, Remaining hours is the differrence between the above two so sometimes the this column can have negative values and whenever there is, the formula gives the incorrect value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is a screenshot and the highlighted row should have -10 in there instead of -1:50. Is anyone able to suggest an alternative please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Nov 2022 07:16:08 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Converting-Decimal-Hours-to-Time-Format-Issue-with-negative/m-p/2902889#M94600</guid>
      <dc:creator>saadat_rda</dc:creator>
      <dc:date>2022-11-14T07:16:08Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Decimal Hours to Time Format (Issue with negative values)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Converting-Decimal-Hours-to-Time-Format-Issue-with-negative/m-p/2906053#M94818</link>
      <description>&lt;P&gt;Hi&amp;nbsp; &lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="444265" data-lia-user-login="saadat_rda" class="lia-mention lia-mention-user"&gt;saadat_rda&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are the steps you can follow：&lt;/P&gt;
&lt;P&gt;1. Create calculated column.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;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 &amp;amp;&amp;amp; _mid&amp;lt;0, "-"&amp;amp;""&amp;amp;(_left+1)&amp;amp;":"&amp;amp;60 +_mid,
_left &amp;gt;=0 &amp;amp;&amp;amp; _mid&amp;gt;=0,_left &amp;amp;":"&amp;amp;_mid,
_left &amp;gt;=0 &amp;amp;&amp;amp; _mid&amp;lt;0,_left +1 &amp;amp;":"&amp;amp; 60 +_mid,
_left &amp;lt;0 &amp;amp;&amp;amp; _mid&amp;gt;=0, _left&amp;amp;":"&amp;amp; _mid,
BLANK()
)

&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Remaining Hours =
var _len=
LEN('Table'[Flag])
var _left=LEFT('Table'[Flag],1)
return
SWITCH(
    TRUE(),
        _len=5&amp;amp;&amp;amp;_left="-","-0"&amp;amp;""&amp;amp;MID([Flag],2,4),
    _len=3,"0"&amp;amp;""&amp;amp;[Flag]&amp;amp;""&amp;amp;"0",
    _len=4,"0"&amp;amp;""&amp;amp;[Flag],
    [Flag]
    )

&lt;/LI-CODE&gt;
&lt;P&gt;2. Result:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards,&lt;/P&gt;
&lt;P&gt;Liu Yang&lt;/P&gt;
&lt;P&gt;If this post &lt;STRONG&gt;helps&lt;/STRONG&gt;, then please consider &lt;EM&gt;Accept it as the solution&lt;/EM&gt; to help the other members find it more quickly&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 09:40:38 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Converting-Decimal-Hours-to-Time-Format-Issue-with-negative/m-p/2906053#M94818</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2022-11-15T09:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Decimal Hours to Time Format (Issue with negative values)</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Converting-Decimal-Hours-to-Time-Format-Issue-with-negative/m-p/2907825#M94925</link>
      <description>&lt;P&gt;Thanks Liu. It worked and I really appreciate this!&lt;/P&gt;</description>
      <pubDate>Tue, 15 Nov 2022 21:56:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Converting-Decimal-Hours-to-Time-Format-Issue-with-negative/m-p/2907825#M94925</guid>
      <dc:creator>saadat_rda</dc:creator>
      <dc:date>2022-11-15T21:56:06Z</dc:date>
    </item>
  </channel>
</rss>

