<?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: Calculate Overlap Period in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-Overlap-Period/m-p/2445006#M65594</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="376323" data-lia-user-login="azeem" class="lia-mention lia-mention-user"&gt;azeem&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can certainly write a measure along these lines, and I would be interested to hear how it performs with your actual dataset.&lt;/P&gt;
&lt;P&gt;You can use GENERATE with GENERATESERIES to create the required list of "second values" per row in a new column. Then select this column and count distinct values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The measure would look something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Total Hours = 
VAR SecondsPerHour = 3600
VAR SecondsPerDay = SecondsPerHour * 24
VAR SecondIndex =
    SELECTCOLUMNS (
        GENERATE (
            Data,
            GENERATESERIES (
                INT ( Data[Start Time] * SecondsPerDay ),
                INT ( Data[End Time] * SecondsPerDay )
            )
        ),
        "@SecondIndex", [Value]
    )
VAR NumSeconds =
    COUNTROWS (
        DISTINCT ( SecondIndex )
    )
VAR Hours = NumSeconds / SecondsPerHour
RETURN
    Hours&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Total Hours v2 = 
VAR SecondsPerHour = 3600
VAR SecondsPerDay = SecondsPerHour * 24
VAR SecondIndex =
    SUMMARIZE (
        GENERATE (
            Data,
            GENERATESERIES (
                INT ( Data[Start Time] * SecondsPerDay ),
                INT ( Data[End Time] * SecondsPerDay )
            )
        ),
        [Value]
    )
VAR NumSeconds =
    COUNTROWS ( SecondIndex )
VAR Hours = NumSeconds / SecondsPerHour
RETURN
    Hours&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We multiply by SecondsPerDay in order to convert serial numbers (where an interval of a day corresponds to a value of 1) into seconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The values created by GENERATESERIES should be well within the Power BI's integer bounds for any conceivable date/time values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing to note is that both the start and end times are included. So if Start Time and End Time are equal, the duration for that row would be one second. This could be tweaked if required.&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;
&lt;P&gt;Owen&lt;/P&gt;</description>
    <pubDate>Fri, 08 Apr 2022 06:18:36 GMT</pubDate>
    <dc:creator>OwenAuger</dc:creator>
    <dc:date>2022-04-08T06:18:36Z</dc:date>
    <item>
      <title>Calculate Overlap Period</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-Overlap-Period/m-p/2443234#M65487</link>
      <description>&lt;P&gt;Hi, I have two columns represent the start time &amp;amp; end time for each activities. Each of the periods are overlapping. I would like to calculate total hours (considering the overlapping periods). The solution that I've found takes too long as I have 10k rows. Therefore, I would like to create a measure using GENERATESERIES for each row for each second and UNION them into a column to DISTINCTCOUNT them to get the total seconds then convert them to total hours (that I think will make the DAX code runs faster). How I could achieve that? Thanks&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>Thu, 07 Apr 2022 11:24:07 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-Overlap-Period/m-p/2443234#M65487</guid>
      <dc:creator>azeem</dc:creator>
      <dc:date>2022-04-07T11:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Overlap Period</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-Overlap-Period/m-p/2445006#M65594</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="376323" data-lia-user-login="azeem" class="lia-mention lia-mention-user"&gt;azeem&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can certainly write a measure along these lines, and I would be interested to hear how it performs with your actual dataset.&lt;/P&gt;
&lt;P&gt;You can use GENERATE with GENERATESERIES to create the required list of "second values" per row in a new column. Then select this column and count distinct values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The measure would look something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Total Hours = 
VAR SecondsPerHour = 3600
VAR SecondsPerDay = SecondsPerHour * 24
VAR SecondIndex =
    SELECTCOLUMNS (
        GENERATE (
            Data,
            GENERATESERIES (
                INT ( Data[Start Time] * SecondsPerDay ),
                INT ( Data[End Time] * SecondsPerDay )
            )
        ),
        "@SecondIndex", [Value]
    )
VAR NumSeconds =
    COUNTROWS (
        DISTINCT ( SecondIndex )
    )
VAR Hours = NumSeconds / SecondsPerHour
RETURN
    Hours&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively:&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Total Hours v2 = 
VAR SecondsPerHour = 3600
VAR SecondsPerDay = SecondsPerHour * 24
VAR SecondIndex =
    SUMMARIZE (
        GENERATE (
            Data,
            GENERATESERIES (
                INT ( Data[Start Time] * SecondsPerDay ),
                INT ( Data[End Time] * SecondsPerDay )
            )
        ),
        [Value]
    )
VAR NumSeconds =
    COUNTROWS ( SecondIndex )
VAR Hours = NumSeconds / SecondsPerHour
RETURN
    Hours&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We multiply by SecondsPerDay in order to convert serial numbers (where an interval of a day corresponds to a value of 1) into seconds.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The values created by GENERATESERIES should be well within the Power BI's integer bounds for any conceivable date/time values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One thing to note is that both the start and end times are included. So if Start Time and End Time are equal, the duration for that row would be one second. This could be tweaked if required.&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;
&lt;P&gt;Owen&lt;/P&gt;</description>
      <pubDate>Fri, 08 Apr 2022 06:18:36 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculate-Overlap-Period/m-p/2445006#M65594</guid>
      <dc:creator>OwenAuger</dc:creator>
      <dc:date>2022-04-08T06:18:36Z</dc:date>
    </item>
  </channel>
</rss>

