<?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: DAX Help: Measure of Working Minutes between two times in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Help-Measure-of-Working-Minutes-between-two-times/m-p/3761022#M146731</link>
    <description>&lt;LI-CODE lang="markup"&gt;As you can see in my table, I have a Calendar_DateRangePicker[IsBusinessDay] field which takes care of Working vs Non Working days.&lt;/LI-CODE&gt;
&lt;P&gt;You can modify my code accordingly to replace the WEEKDAY&amp;nbsp; filter with your IsBusinessDay filter.&lt;/P&gt;</description>
    <pubDate>Wed, 13 Mar 2024 14:51:41 GMT</pubDate>
    <dc:creator>lbendlin</dc:creator>
    <dc:date>2024-03-13T14:51:41Z</dc:date>
    <item>
      <title>DAX Help: Measure of Working Minutes between two times</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Help-Measure-of-Working-Minutes-between-two-times/m-p/3749702#M146253</link>
      <description>&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P class=""&gt;Howdy there.&amp;nbsp; I'm stuck.&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;I'm trying to build a DAX measure that will calculate the working minutes between two datetime objects but just can't figure it out. Has anyone solved this before? I feel like it should be easy, I just can't wrap my head around the solution.&lt;/P&gt;&lt;P class=""&gt;Below is my attempt, but it's returning working minutes for the entire day, not just between the start and end time for each day:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;img /&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P class=""&gt;For the above records, here's what I expect the value to show:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Id&lt;/TD&gt;&lt;TD&gt;CreatedTime&lt;/TD&gt;&lt;TD&gt;postedTime&lt;/TD&gt;&lt;TD&gt;workingMinutes 0700-1630&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;113670&lt;/TD&gt;&lt;TD&gt;2024-02-27 11:55:00.000 -06:00&lt;/TD&gt;&lt;TD&gt;2024-02-28 10:06:36.000 -06:00&lt;/TD&gt;&lt;TD&gt;461&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;113720&lt;/TD&gt;&lt;TD&gt;2024-02-28 06:59:00.000 -06:00&lt;/TD&gt;&lt;TD&gt;2024-02-28 09:09:32.000 -06:00&lt;/TD&gt;&lt;TD&gt;129&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;113672&lt;/TD&gt;&lt;TD&gt;2024-02-27 11:56:00.000 -06:00&lt;/TD&gt;&lt;TD&gt;2024-02-27 12:08:16.000 -06:00&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;113662&lt;/TD&gt;&lt;TD&gt;2024-02-27 10:57:00.000 -06:00&lt;/TD&gt;&lt;TD&gt;2024-02-27 11:14:24.000 -06:00&lt;/TD&gt;&lt;TD&gt;17&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;113601&lt;/TD&gt;&lt;TD&gt;2024-02-26 15:31:00.000 -06:00&lt;/TD&gt;&lt;TD&gt;2024-02-27 07:49:56.000 -06:00&lt;/TD&gt;&lt;TD&gt;108&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;113361&lt;/TD&gt;&lt;TD&gt;2024-02-22 11:53:00.000 -06:00&lt;/TD&gt;&lt;TD&gt;2024-02-26 07:31:38.000 -06:00&lt;/TD&gt;&lt;TD&gt;878&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;113359&lt;/TD&gt;&lt;TD&gt;2024-02-22 11:44:00.000 -06:00&lt;/TD&gt;&lt;TD&gt;2024-02-22 14:53:08.000 -06:00&lt;/TD&gt;&lt;TD&gt;189&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;113340&lt;/TD&gt;&lt;TD&gt;2024-02-22 09:58:00.000 -06:00&lt;/TD&gt;&lt;TD&gt;2024-02-22 14:33:42.000 -06:00&lt;/TD&gt;&lt;TD&gt;275&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;113392&lt;/TD&gt;&lt;TD&gt;2024-02-22 13:19:00.000 -06:00&lt;/TD&gt;&lt;TD&gt;2024-02-22 13:21:34.000 -06:00&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;113195&lt;/TD&gt;&lt;TD&gt;2024-02-20 13:02:00.000 -06:00&lt;/TD&gt;&lt;TD&gt;2024-02-20 13:14:18.000 -06:00&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;113142&lt;/TD&gt;&lt;TD&gt;2024-02-20 09:02:00.000 -06:00&lt;/TD&gt;&lt;TD&gt;2024-02-20 10:12:01.000 -06:00&lt;/TD&gt;&lt;TD&gt;70&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P class=""&gt;Working Hours are typically defined as 0700-1630 CST.&lt;/P&gt;&lt;P class=""&gt;Here's the DAX I was trying so far, but I know it's, to an extent, not even directionally accurate for how I'm supposed to do it. (In the above screenshot, I expect the Total line to be the SumTotal of each individual Load Id value.)&lt;/P&gt;&lt;PRE&gt;_m_CreatedPosted_Time_cgpt = 
var createdTime = min(####Data[createdTime]) 
var PostedTime = min(###LoadPostingID[PostedTime])
RETURN
-- Calculate the total working minutes between StartDateTime and EndDateTime
SUMX (
    -- Generate a row for each date between StartDateTime and EndDateTime
        CALCULATETABLE (
        Calendar_DateRangePicker,
        DATESBETWEEN (
            Calendar_DateRangePicker[DateId],
            createdTime,
            PostedTime
        ),
        Calendar_DateRangePicker[IsBusinessDay####] = TRUE ()
    ),
    -- For each date, calculate the working minutes based on business hours
    IF (
        Calendar_DateRangePicker[DateId] = createdTime &amp;amp;&amp;amp; HOUR(createdTime) &amp;lt; hour(Calendar_DateRangePicker[StartTime]), // If createdTime is before 07:00
        IF (
            HOUR(postedTime) &amp;gt;= hour(Calendar_DateRangePicker[EndTime]), // If postedTime is after or at 16:30
            DATEDIFF(Calendar_DateRangePicker[StartTime], Calendar_DateRangePicker[EndTime], MINUTE),
            DATEDIFF(Calendar_DateRangePicker[StartTime], postedTime, MINUTE)
        ),
        IF (
            Calendar_DateRangePicker[DateId] = postedTime &amp;amp;&amp;amp; HOUR(postedTime) &amp;gt;= hour(Calendar_DateRangePicker[EndTime]), // If postedTime is after or at 16:30
            DATEDIFF(Calendar_DateRangePicker[StartTime], Calendar_DateRangePicker[EndTime], MINUTE),
            DATEDIFF(Calendar_DateRangePicker[StartTime], Calendar_DateRangePicker[EndTime], MINUTE)
        )
    )
)&lt;/PRE&gt;&lt;P class=""&gt;I do have a Calendar table which includes the Start and End working time for each day, and indicates if a day is a Business Day. (The business hours are generally 0700-1630.)&lt;/P&gt;&lt;P class=""&gt;Here's the relevant tables from the data model:&lt;/P&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;img /&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;I feel the answer in here is something with a Calculated Table, but I can't figure out how that is supposed to work.&lt;/P&gt;&lt;P class=""&gt;*After I get the answer I want here, I'll then get the Count of values so I can run the Average. I do want to have a measure that's just Totals, though, so I could use that for other things if needed, for why I'm not trying to get the Average directly in this DAX.&lt;/P&gt;&lt;P class=""&gt;&amp;nbsp;&lt;/P&gt;&lt;P class=""&gt;Appreciate any help you can provide!&lt;/P&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;DIV class=""&gt;&lt;BR /&gt;&lt;BR /&gt;*This is a crosspost to the below Reddit Post: &lt;A href="https://www.reddit.com/r/PowerBI/comments/1b9608h/dax_help_measure_of_working_minutes_between_two/" target="_blank" rel="noopener"&gt;https://www.reddit.com/r/PowerBI/comments/1b9608h/dax_help_measure_of_working_minutes_between_two/&lt;/A&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 07 Mar 2024 21:48:34 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Help-Measure-of-Working-Minutes-between-two-times/m-p/3749702#M146253</guid>
      <dc:creator>eaglesilo</dc:creator>
      <dc:date>2024-03-07T21:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Help: Measure of Working Minutes between two times</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Help-Measure-of-Working-Minutes-between-two-times/m-p/3752261#M146354</link>
      <description>&lt;P&gt;You say working minutes but your second timestamp is on seconds granularity.&amp;nbsp; Please clarify. As you can see we have some slight disagreements on the duration.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;You need to decide if you want to include or exclude the minute of the postedTime&amp;nbsp; timestamp.&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What should happen when the time interval spreads over weekends and holidays? For now I assume you observe weekends on saturday and sunday, and have no holidays.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;wm =
VAR a =
    GENERATESERIES (
        ROUNDDOWN ( [CreatedTime] * 1440, 0 ),
        ROUNDDOWN ( [postedTime] * 1440, 0 )
    )
VAR b =
    ADDCOLUMNS (
        FILTER ( CALENDAR ( [CreatedTime], [postedTime] ), WEEKDAY ( [Date], 2 ) &amp;lt; 6 ),
        "v", ROUNDDOWN ( [Date], 0 ) * 1440
    )
VAR c =
    GENERATE ( b, GENERATESERIES ( [v] + 420, [v] + 990 ) )
RETURN
    COUNTROWS ( INTERSECT ( a, SELECTCOLUMNS ( c, "Value", [Value] ) ) )&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Mar 2024 01:40:16 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Help-Measure-of-Working-Minutes-between-two-times/m-p/3752261#M146354</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2024-03-09T01:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Help: Measure of Working Minutes between two times</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Help-Measure-of-Working-Minutes-between-two-times/m-p/3760543#M146710</link>
      <description>&lt;P&gt;Thank you for the reply.&amp;nbsp; As you can see in my table, I have a Calendar_DateRangePicker[IsBusinessDay] field which takes care of Working vs Non Working days.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the various screenshots, I did not truncate the times to the nearest minute, but if we need to do that before we can proceed with getting to working minutes, we can.&amp;nbsp; You can choose to round in whichever direciton you wish for now.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 11:54:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Help-Measure-of-Working-Minutes-between-two-times/m-p/3760543#M146710</guid>
      <dc:creator>eaglesilo</dc:creator>
      <dc:date>2024-03-13T11:54:54Z</dc:date>
    </item>
    <item>
      <title>Re: DAX Help: Measure of Working Minutes between two times</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Help-Measure-of-Working-Minutes-between-two-times/m-p/3761022#M146731</link>
      <description>&lt;LI-CODE lang="markup"&gt;As you can see in my table, I have a Calendar_DateRangePicker[IsBusinessDay] field which takes care of Working vs Non Working days.&lt;/LI-CODE&gt;
&lt;P&gt;You can modify my code accordingly to replace the WEEKDAY&amp;nbsp; filter with your IsBusinessDay filter.&lt;/P&gt;</description>
      <pubDate>Wed, 13 Mar 2024 14:51:41 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/DAX-Help-Measure-of-Working-Minutes-between-two-times/m-p/3761022#M146731</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2024-03-13T14:51:41Z</dc:date>
    </item>
  </channel>
</rss>

