<?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: Average Time Measure in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-Time-Measure/m-p/1156770#M17684</link>
    <description>&lt;P&gt;Change your data model so the sleep onset is captured by a Datetime field, not just a time field.&amp;nbsp; Or have logic that checks if the date value is the same for your timestamps.&lt;/P&gt;</description>
    <pubDate>Fri, 12 Jun 2020 23:04:21 GMT</pubDate>
    <dc:creator>lbendlin</dc:creator>
    <dc:date>2020-06-12T23:04:21Z</dc:date>
    <item>
      <title>Average Time Measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-Time-Measure/m-p/1156609#M17676</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Im looking for a measure to calculate an average time that my clients fall asleep at night. I have used the following DAX formula for wake up time which is satisfactory:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Sleep Onset Time Avg = FORMAT(CALCULATE(AVERAGE(FacTBLsleepwatch[Sleep Onset Time (hh:mm)])),"HH:mm")&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This works for wake up time as they wake up on the same day between 6am and 9am and so an average somewhere between these points is correct.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, it doesnt work for sleep onset in the evening. If they fall asleep at 11pm on one night, and 3am the next, the above measure seems to set these times in chronological order, and would come up with an average sleep onset value of 1pm (in the afternoon), rather than 1am (in the morning - which is the value I would want).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know a way to allow DAX to identify when the value to be calcualted moves past the 24 hour clock to the next day. The data is saved in query as date/time in the single column for sleep onset time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jun 2020 20:05:18 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-Time-Measure/m-p/1156609#M17676</guid>
      <dc:creator>Will_740</dc:creator>
      <dc:date>2020-06-12T20:05:18Z</dc:date>
    </item>
    <item>
      <title>Re: Average Time Measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-Time-Measure/m-p/1156770#M17684</link>
      <description>&lt;P&gt;Change your data model so the sleep onset is captured by a Datetime field, not just a time field.&amp;nbsp; Or have logic that checks if the date value is the same for your timestamps.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Jun 2020 23:04:21 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-Time-Measure/m-p/1156770#M17684</guid>
      <dc:creator>lbendlin</dc:creator>
      <dc:date>2020-06-12T23:04:21Z</dc:date>
    </item>
    <item>
      <title>Re: Average Time Measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-Time-Measure/m-p/1157483#M17714</link>
      <description>&lt;P&gt;This was an interesting challenge, and the expression below should get your desired result.&amp;nbsp; It takes each row (onset time) and converts it to minutes.&amp;nbsp; If it is &amp;lt; 12 PM, it adds 24 hrs (in minutes) to it, before taking the average.&amp;nbsp; Once the average is calculated, it subtracts the 24 hrs back off (if &amp;gt;midnight), and converts the minutes back to hours and minutes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Correct Average =&lt;BR /&gt;VAR avgtimeinminutes =&lt;BR /&gt;AVERAGEX (&lt;BR /&gt;Sleep,&lt;BR /&gt;VAR timeinminutes =&lt;BR /&gt;HOUR ( Sleep[Onset] ) * 60&lt;BR /&gt;+ MINUTE ( Sleep[Onset] )&lt;BR /&gt;VAR adjminutes =&lt;BR /&gt;IF ( timeinminutes &amp;lt; 720, timeinminutes + 1440, timeinminutes )&lt;BR /&gt;RETURN&lt;BR /&gt;adjminutes&lt;BR /&gt;)&lt;BR /&gt;VAR avgtimecorrection =&lt;BR /&gt;IF ( avgtimeinminutes &amp;lt; 1440, avgtimeinminutes, avgtimeinminutes - 1440 )&lt;BR /&gt;VAR avghour =&lt;BR /&gt;QUOTIENT ( avgtimecorrection, 60 )&lt;BR /&gt;VAR avgmin =&lt;BR /&gt;MOD ( avgtimecorrection, 60 )&lt;BR /&gt;RETURN&lt;BR /&gt;FORMAT ( TIME ( avghour, avgmin, 0 ), "h:mm am/pm" )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this works for you, please mark it as the solution.&amp;nbsp; Kudos are appreciated too.&amp;nbsp; Please let me know if not.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Pat&lt;/P&gt;</description>
      <pubDate>Sun, 14 Jun 2020 02:00:49 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-Time-Measure/m-p/1157483#M17714</guid>
      <dc:creator>mahoneypat</dc:creator>
      <dc:date>2020-06-14T02:00:49Z</dc:date>
    </item>
    <item>
      <title>Re: Average Time Measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-Time-Measure/m-p/1163981#M17865</link>
      <description>&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Hi Pat,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Thanks for taking the time to think about this, it worked really well!&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Best Regards,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Will&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 16 Jun 2020 19:26:20 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-Time-Measure/m-p/1163981#M17865</guid>
      <dc:creator>Will_740</dc:creator>
      <dc:date>2020-06-16T19:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: Average Time Measure</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-Time-Measure/m-p/2019084#M44944</link>
      <description>&lt;P&gt;Hey Pat&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is great and question Is there a way to add seconds into this measure?&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 15:54:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Average-Time-Measure/m-p/2019084#M44944</guid>
      <dc:creator>OpenMike13</dc:creator>
      <dc:date>2021-08-16T15:54:32Z</dc:date>
    </item>
  </channel>
</rss>

