<?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: hour difference without workhours in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/hour-difference-without-workhours/m-p/3467968#M132380</link>
    <description>&lt;P&gt;your work is amazing !! but how to shift to calculate minutes&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 10 Oct 2023 05:48:46 GMT</pubDate>
    <dc:creator>mina97</dc:creator>
    <dc:date>2023-10-10T05:48:46Z</dc:date>
    <item>
      <title>hour difference without workhours</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/hour-difference-without-workhours/m-p/3454883#M131678</link>
      <description>&lt;P&gt;i have the following data&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;start date&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;end date&lt;/TD&gt;&lt;TD&gt;status&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2023-07-02 6:01:00&lt;/TD&gt;&lt;TD&gt;2023-07-04 15:10:11&lt;/TD&gt;&lt;TD&gt;confirmed&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1- i want to calculate the time difference in hours only if it is between 8:00:00 and 17:10:00 so the example upove should be &lt;STRONG&gt;25&lt;/STRONG&gt; hours&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2- and i want the same thing but in minutes&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;please help me and thank you&lt;/STRONG&gt;&lt;/U&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Oct 2023 06:46:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/hour-difference-without-workhours/m-p/3454883#M131678</guid>
      <dc:creator>mina97</dc:creator>
      <dc:date>2023-10-01T06:46:26Z</dc:date>
    </item>
    <item>
      <title>Re: hour difference without workhours</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/hour-difference-without-workhours/m-p/3454982#M131682</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="612491" data-lia-user-login="mina97" class="lia-mention lia-mention-user"&gt;mina97&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have attached a PBIX with suggested calculated colums in DAX for Work Hours and Work Minutes.&lt;/P&gt;
&lt;P&gt;The code is a bit long-winded in order to capture the required logic.&lt;/P&gt;
&lt;P&gt;I assumed:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Weekends/holidays do not need to be excluded. If you do, you would need to adjust and use NETWORKDAYS.&lt;/LI&gt;
&lt;LI&gt;You want to round down to the nearest integer.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Here is the expression for &lt;STRONG&gt;Work Hours (Work Minutes &lt;/STRONG&gt;is similar):&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Work Hours = 
-- Working Start and End time 
VAR WorkTimeStart = TIME ( 08, 00, 00 )
VAR WorkTimeEnd = TIME ( 17, 10, 10 )
VAR WorkingHours = ( WorkTimeEnd - WorkTimeStart )

-- Start and End date/time on current row
VAR StartingDateTime = Data[start date]
VAR EndingDateTime   = Data[end date]

VAR StartingTime= StartingDateTime - TRUNC ( StartingDateTime )
VAR StartingDate = StartingDateTime - StartingTime

VAR EndingTime = EndingDateTime - TRUNC ( EndingDateTime )
VAR EndingDate = EndingDateTime - EndingTime

-- Adjust start/end times to fall within working hours.
VAR StartingTimeEffective =
    MIN (
        MAX ( StartingTime, WorkTimeStart ),
        WorkTimeEnd
    )
VAR EndingTimeEffective =
    MAX (
        MIN ( EndingTime, WorkTimeEnd ),
        WorkTimeStart
    )
-- Adjust for hours not worked on StartingDate
--   StartingTimeOffset will always be &amp;lt;= 0
VAR StartingTimeOffset =
    WorkTimeStart - StartingTimeEffective
-- Adjust for hours not worked on EndingDate
--   EndingTimeOffset will always be &amp;lt;= 0
VAR EndingTimeOffset =
    EndingTimeEffective - WorkTimeEnd
VAR DayCount =
    EndingDate - StartingDate + 1
VAR TotalTimeInDays =
    DayCount * WorkingHours + StartingTimeOffset + EndingTimeOffset
VAR TotalTimeInHours =
    TotalTimeInDays * 24
VAR TotalTimeInHoursRounded =
    ROUNDDOWN ( TotalTimeInHours, 0 )
RETURN
    TotalTimeInHoursRounded&lt;/LI-CODE&gt;
&lt;P&gt;This is a good article on a similar but different calculation:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.sqlbi.com/blog/alberto/2019/03/25/using-dax-with-datetime-values/" target="_blank"&gt;https://www.sqlbi.com/blog/alberto/2019/03/25/using-dax-with-datetime-values/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this work for you?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;</description>
      <pubDate>Sun, 01 Oct 2023 11:51:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/hour-difference-without-workhours/m-p/3454982#M131682</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2023-10-01T11:51:51Z</dc:date>
    </item>
    <item>
      <title>Re: hour difference without workhours</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/hour-difference-without-workhours/m-p/3466751#M132327</link>
      <description>&lt;P&gt;thank you it helped&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 12:31:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/hour-difference-without-workhours/m-p/3466751#M132327</guid>
      <dc:creator>mina97</dc:creator>
      <dc:date>2023-10-09T12:31:56Z</dc:date>
    </item>
    <item>
      <title>Re: hour difference without workhours</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/hour-difference-without-workhours/m-p/3466770#M132328</link>
      <description>&lt;P&gt;but you did not exclude the out of working hours&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 12:41:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/hour-difference-without-workhours/m-p/3466770#M132328</guid>
      <dc:creator>mina97</dc:creator>
      <dc:date>2023-10-09T12:41:07Z</dc:date>
    </item>
    <item>
      <title>Re: hour difference without workhours</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/hour-difference-without-workhours/m-p/3467619#M132358</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="612491" data-lia-user-login="mina97" class="lia-mention lia-mention-user"&gt;mina97&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Glad it helped.&lt;/P&gt;
&lt;P&gt;The expression does just count working hours.&lt;/P&gt;
&lt;P&gt;The variable &lt;STRONG&gt;TotalTimeInDays&amp;nbsp;&lt;/STRONG&gt;does just include working hours, with an adjustment for the start/end times.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But let me know if you have a specific example where it is not working.&lt;/P&gt;
&lt;P&gt;Regards&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 22:38:57 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/hour-difference-without-workhours/m-p/3467619#M132358</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2023-10-09T22:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: hour difference without workhours</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/hour-difference-without-workhours/m-p/3467968#M132380</link>
      <description>&lt;P&gt;your work is amazing !! but how to shift to calculate minutes&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 05:48:46 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/hour-difference-without-workhours/m-p/3467968#M132380</guid>
      <dc:creator>mina97</dc:creator>
      <dc:date>2023-10-10T05:48:46Z</dc:date>
    </item>
    <item>
      <title>Re: hour difference without workhours</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/hour-difference-without-workhours/m-p/3468553#M132407</link>
      <description>&lt;P&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;The PBIX attached earlier has a "Work Minutes" calculated column that is essentially Work Hours * 60.&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 10:33:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/hour-difference-without-workhours/m-p/3468553#M132407</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2023-10-10T10:33:50Z</dc:date>
    </item>
    <item>
      <title>Re: hour difference without workhours</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/hour-difference-without-workhours/m-p/3468579#M132409</link>
      <description>&lt;P&gt;i can not download the file &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 10:48:00 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/hour-difference-without-workhours/m-p/3468579#M132409</guid>
      <dc:creator>mina97</dc:creator>
      <dc:date>2023-10-10T10:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: hour difference without workhours</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/hour-difference-without-workhours/m-p/3468604#M132411</link>
      <description>&lt;P&gt;That's odd - it's in my post above, but I reattached here in case that helps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the link created by the forum:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://community.fabric.microsoft.com/oxcrx34285/attachments/oxcrx34285/DAXCommands/131682/1/Work%20Hours%20Calculation.pbix" target="_blank"&gt;https://community.fabric.microsoft.com/oxcrx34285/attachments/oxcrx34285/DAXCommands/131682/1/Work%20Hours%20Calculation.pbix&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 11:03:36 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/hour-difference-without-workhours/m-p/3468604#M132411</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2023-10-10T11:03:36Z</dc:date>
    </item>
    <item>
      <title>Re: hour difference without workhours</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/hour-difference-without-workhours/m-p/3468654#M132416</link>
      <description>&lt;P&gt;thank you so much&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Oct 2023 11:27:37 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/hour-difference-without-workhours/m-p/3468654#M132416</guid>
      <dc:creator>mina97</dc:creator>
      <dc:date>2023-10-10T11:27:37Z</dc:date>
    </item>
  </channel>
</rss>

