<?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: Calculated column for first occurrence during different times of the day in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-column-for-first-occurrence-during-different-times-of/m-p/4002520#M156207</link>
    <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="432682" data-lia-user-login="JenWilson" class="lia-mention lia-mention-user"&gt;JenWilson&lt;/a&gt;&amp;nbsp;- The DAX below will work in a calculated column (you just need to change the table names):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Diff = 
VAR period = Query1[ProdSchedule]
VAR max_start_time =
    CALCULATE (
        MAX ( Query1[BeginTime] ),
        ALLEXCEPT ( Query1, Query1[ProdSchedule] )
    )
VAR diff = Query1[ProdScheduleStartTime] - Query1[BeginTime]
VAR calc =
    IF (
        Query1[ProdSchedule] = period
            &amp;amp;&amp;amp; Query1[BeginTime] = max_start_time,
        CALCULATE ( diff )
    )
RETURN
    calc&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Screenshot to show it is working:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;If this works, please mark it as the solution.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 20 Jun 2024 16:58:53 GMT</pubDate>
    <dc:creator>mark_endicott</dc:creator>
    <dc:date>2024-06-20T16:58:53Z</dc:date>
    <item>
      <title>Calculated column for first occurrence during different times of the day</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-column-for-first-occurrence-during-different-times-of/m-p/4002460#M156206</link>
      <description>&lt;P&gt;I am looking to create a new column (manual example called Diff added to screen shot below for what I am looking for. It can be in query or directly in the table. I would like the new column to calculate the time difference between the time in the ProdScheduleStartTimesbased and the BeginTime column but also based on the BeginDate. Perhaps using the combined column StartTime would work better? It only needs to calculate the time difference for the first occurance (for each date) of each item listed in the each ProductionSchedule (Period1, Period 2, etc.) I have manually added what I am looking for to the far right (the Diff column). Basically, I want to see how long it took for the first production to start against when the shift (Period) began. In the first line, you can see that Period 1 starts at 5:00:00 AM, but the first production job didn't start running until 5:26:37 AM so I want to see the difference value of 00:26:37. Farther down, as another example, you can see that Period 2 starts at 7:05:00 AM, but the first production job for that periond didn't start running until 7:09:06 AM, so I want to see the difference value of 00:04:06.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone please help me come up with a solution to this? Thank you!&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2024 16:03:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-column-for-first-occurrence-during-different-times-of/m-p/4002460#M156206</guid>
      <dc:creator>JenWilson</dc:creator>
      <dc:date>2024-06-20T16:03:43Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated column for first occurrence during different times of the day</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-column-for-first-occurrence-during-different-times-of/m-p/4002520#M156207</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="432682" data-lia-user-login="JenWilson" class="lia-mention lia-mention-user"&gt;JenWilson&lt;/a&gt;&amp;nbsp;- The DAX below will work in a calculated column (you just need to change the table names):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Diff = 
VAR period = Query1[ProdSchedule]
VAR max_start_time =
    CALCULATE (
        MAX ( Query1[BeginTime] ),
        ALLEXCEPT ( Query1, Query1[ProdSchedule] )
    )
VAR diff = Query1[ProdScheduleStartTime] - Query1[BeginTime]
VAR calc =
    IF (
        Query1[ProdSchedule] = period
            &amp;amp;&amp;amp; Query1[BeginTime] = max_start_time,
        CALCULATE ( diff )
    )
RETURN
    calc&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Screenshot to show it is working:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;If this works, please mark it as the solution.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2024 16:58:53 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-column-for-first-occurrence-during-different-times-of/m-p/4002520#M156207</guid>
      <dc:creator>mark_endicott</dc:creator>
      <dc:date>2024-06-20T16:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated column for first occurrence during different times of the day</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-column-for-first-occurrence-during-different-times-of/m-p/4002638#M156208</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="343036" data-lia-user-login="mark_endicott" class="lia-mention lia-mention-user"&gt;mark_endicott&lt;/a&gt;&amp;nbsp;Hi, thanks for your quick response.&amp;nbsp; I actually need the time calculations to be based off of the earlier time occurance so I changed MAX to MIN. However, it is only doing the calculation on one date - the date and period with the smallest varience I assume. So, I'm guessing that I need to added some addtional details around the date as well?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jun 2024 18:14:50 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-column-for-first-occurrence-during-different-times-of/m-p/4002638#M156208</guid>
      <dc:creator>JenWilson</dc:creator>
      <dc:date>2024-06-20T18:14:50Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated column for first occurrence during different times of the day</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-column-for-first-occurrence-during-different-times-of/m-p/4002726#M156209</link>
      <description>&lt;P&gt;This is where I am at with the following DAX code. I need to to calculate for each date and each period. What do I need to add to my DAX formula to make this work?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Difference =&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;VAR&lt;/SPAN&gt; &lt;SPAN&gt;period&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;Eagle1_and_2&lt;/SPAN&gt;&lt;SPAN&gt;[ProductionSchedule]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;VAR&lt;/SPAN&gt; &lt;SPAN&gt;min_start_time&lt;/SPAN&gt;&lt;SPAN&gt; =&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;CALCULATE&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;MIN&lt;/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p; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;Eagle1_and_2&lt;/SPAN&gt;&lt;SPAN&gt;[ProductionSchedule]&lt;/SPAN&gt;&lt;SPAN&gt;= &lt;/SPAN&gt;&lt;SPAN&gt;period&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;amp;&amp;amp; &lt;/SPAN&gt;&lt;SPAN&gt;Eagle1_and_2&lt;/SPAN&gt;&lt;SPAN&gt;[BeginTime]&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;min_start_time&lt;/SPAN&gt;&lt;SPAN&gt;,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;CALCULATE&lt;/SPAN&gt;&lt;SPAN&gt; ( &lt;/SPAN&gt;&lt;SPAN&gt;diff&lt;/SPAN&gt;&lt;SPAN&gt; )&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; )&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;RETURN&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;calc&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&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, 20 Jun 2024 19:36:28 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-column-for-first-occurrence-during-different-times-of/m-p/4002726#M156209</guid>
      <dc:creator>JenWilson</dc:creator>
      <dc:date>2024-06-20T19:36:28Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated column for first occurrence during different times of the day</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-column-for-first-occurrence-during-different-times-of/m-p/4003700#M156210</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="432682" data-lia-user-login="JenWilson" class="lia-mention lia-mention-user"&gt;JenWilson&lt;/a&gt;&amp;nbsp;- Sorry for the use of MAX in my code, I didnt read your requirements properly and one of the DIFF values in your screenshot was not on the MAX or MIN (05:26:37 AM). But that's still my mistake.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your screenshot only had one day too, so it wasnt clear this would need to cover multiple dates, my code below has this updated - you just need to add your "Date" column into the ALLEXCEPT().&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Diff = 
VAR period = Query1[ProdSchedule]
VAR min_start_time =
    CALCULATE (
        min ( Query1[BeginTime] ),
        ALLEXCEPT ( Query1, Query1[ProdSchedule], Query1[Date] )
    )
VAR diff = Query1[ProdScheduleStartTime] - Query1[BeginTime]
VAR calc =
    IF (
        Query1[ProdSchedule] = period
            &amp;amp;&amp;amp; Query1[BeginTime] = min_start_time,
        CALCULATE ( diff )
    )
RETURN
    calc&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;If this works, please accept as the solution.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2024 09:00:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-column-for-first-occurrence-during-different-times-of/m-p/4003700#M156210</guid>
      <dc:creator>mark_endicott</dc:creator>
      <dc:date>2024-06-21T09:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated column for first occurrence during different times of the day</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-column-for-first-occurrence-during-different-times-of/m-p/4004434#M156287</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="343036" data-lia-user-login="mark_endicott" class="lia-mention lia-mention-user"&gt;mark_endicott&lt;/a&gt;&amp;nbsp;, Yes, this worked pefectly! Thank you so much! Now, is there a way to subtract this value from another measure that I have in my data set? I'm guessing not.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jun 2024 16:08:14 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-column-for-first-occurrence-during-different-times-of/m-p/4004434#M156287</guid>
      <dc:creator>JenWilson</dc:creator>
      <dc:date>2024-06-21T16:08:14Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated column for first occurrence during different times of the day</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-column-for-first-occurrence-during-different-times-of/m-p/4006474#M156834</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="343036" data-lia-user-login="mark_endicott" class="lia-mention lia-mention-user"&gt;mark_endicott&lt;/a&gt;&amp;nbsp;,Thanks for your quick reply, I'll add more.&lt;/P&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="432682" data-lia-user-login="JenWilson" class="lia-mention lia-mention-user"&gt;JenWilson&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Regarding your question, do you want to create another measure or calculated column to calculate the difference? If it is a measure, since you cannot directly reference the column name in the measure, you need to use an aggregate function to reference the column.&lt;/P&gt;
&lt;P&gt;Something like this.&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;Difference = [Measure] - MAX('Table'[Diff])&lt;/LI-CODE&gt;
&lt;P&gt;If I understood wrongly, please provide more information.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jun 2024 08:05:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-column-for-first-occurrence-during-different-times-of/m-p/4006474#M156834</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2024-06-24T08:05:06Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated column for first occurrence during different times of the day</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-column-for-first-occurrence-during-different-times-of/m-p/4006528#M156836</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="432682" data-lia-user-login="JenWilson" class="lia-mention lia-mention-user"&gt;JenWilson&lt;/a&gt;&amp;nbsp;- Great to hear it worked. Could you mark my message with the MIN change as the solution? It answered your original query.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;With regards to subtracting it from a measure in your model,&amp;nbsp;Anonymous&lt;/a&gt;&amp;nbsp;has given an option, but we would need to know what you are trying to acheive to get the full answer.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jun 2024 08:32:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-column-for-first-occurrence-during-different-times-of/m-p/4006528#M156836</guid>
      <dc:creator>mark_endicott</dc:creator>
      <dc:date>2024-06-24T08:32:56Z</dc:date>
    </item>
    <item>
      <title>Re: Calculated column for first occurrence during different times of the day</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-column-for-first-occurrence-during-different-times-of/m-p/4009371#M157615</link>
      <description>&lt;P&gt;Anonymous&lt;/a&gt;&amp;nbsp;thank you for your response. I ended up coming up with another approach for my second request. thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2024 15:01:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculated-column-for-first-occurrence-during-different-times-of/m-p/4009371#M157615</guid>
      <dc:creator>JenWilson</dc:creator>
      <dc:date>2024-06-25T15:01:43Z</dc:date>
    </item>
  </channel>
</rss>

