<?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: Subtract the min and max value for each date in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-the-min-and-max-value-for-each-date/m-p/2281602#M55832</link>
    <description>&lt;P&gt;Hello ValtteriN,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately this does not work for multiple days selected, which is the reason I need it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Doing it over a single day is actually quite easy for me as I already have measures calculating the first value and the last value over the interval I chose, this breaks down once I choose multiple days, of course, because it takes the ealiert hour of the first day and the latest hour of the last day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 13 Jan 2022 12:33:06 GMT</pubDate>
    <dc:creator>icbd</dc:creator>
    <dc:date>2022-01-13T12:33:06Z</dc:date>
    <item>
      <title>Subtract the min and max value for each date</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-the-min-and-max-value-for-each-date/m-p/2280344#M55779</link>
      <description>&lt;P&gt;Good day everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been hacking away at this particular problem for a little bit. I would like to do two different things.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First, I would like to calculate actual runtime of a machine according to my filters. I have a date column, and an hour (displayed as a decimal number) column. I also have a calendar table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am trying to achieve, is for the selected dates in my date filter:&lt;/P&gt;&lt;P&gt;For each date, subtract the MIN value for the hours to the MAX value, and sum this. Example below&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;Hours&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2021-10-13&lt;/TD&gt;&lt;TD&gt;&amp;nbsp; &amp;nbsp;7.5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2021-10-13&lt;/TD&gt;&lt;TD&gt;&amp;nbsp; &amp;nbsp;23.25&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2021-10-14&lt;/TD&gt;&lt;TD&gt;&amp;nbsp; &amp;nbsp;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2021-10-14&lt;/TD&gt;&lt;TD&gt;&amp;nbsp; &amp;nbsp;23&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The result, for the above example, should be 30.75 hours. Getting the result for single day is easy with the min max functions but I have yet to find a way to make this work reliably with multiple days.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second thing I am trying to achieve is to calculate the planned time. I know the length of each shift, I have 3 shifts per day (but not always).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I made a column which has a ShiftId (1 for day, 2 for evening, 3 for night) and another column that combines this with the date such as I would have, for today 12022-01-12, 22022-01-12, 32022-01-12 to be able to do some DISTINCTCOUNT for the number of shifts. The shifts are not the same length.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The planned time calculation should work according to how ever many date are selected in my filter.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The night shift is 6.5 hours, day shift is 7.5 hours and evening shift is 7 hours.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Say I have two days, one with all three shifts and another with just evening and day, my total should come out to:&lt;/P&gt;&lt;P&gt;6.5+7.5+7+7.5+7=35.5 hours.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That works perfect when I look at past data, but if I want today's data and the day isn't done:&lt;/P&gt;&lt;P&gt;Night shift is finished (6.5)+Day shift is finished(7.5)+Wherever I am in the shift right now = planned time as of now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this makes sense. Thanks to any and all that can provide an input, I'm quite new to this.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jan 2022 22:28:59 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-the-min-and-max-value-for-each-date/m-p/2280344#M55779</guid>
      <dc:creator>icbd</dc:creator>
      <dc:date>2022-01-12T22:28:59Z</dc:date>
    </item>
    <item>
      <title>Re: Subtract the min and max value for each date</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-the-min-and-max-value-for-each-date/m-p/2280402#M55781</link>
      <description>&lt;P&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;Here is one way to calculate MinMax values:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;MinMax = &lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;cdate&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;SELECTEDVALUE&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;MinMax[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gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;return&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;minV&lt;/SPAN&gt;&lt;SPAN&gt;-&lt;/SPAN&gt;&lt;SPAN&gt;maxV&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;For the shift calculation I would need some sample data to visualize the problem.&lt;BR /&gt;&lt;BR /&gt;I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 12 Jan 2022 23:21:30 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-the-min-and-max-value-for-each-date/m-p/2280402#M55781</guid>
      <dc:creator>ValtteriN</dc:creator>
      <dc:date>2022-01-12T23:21:30Z</dc:date>
    </item>
    <item>
      <title>Re: Subtract the min and max value for each date</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-the-min-and-max-value-for-each-date/m-p/2281602#M55832</link>
      <description>&lt;P&gt;Hello ValtteriN,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Unfortunately this does not work for multiple days selected, which is the reason I need it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Doing it over a single day is actually quite easy for me as I already have measures calculating the first value and the last value over the interval I chose, this breaks down once I choose multiple days, of course, because it takes the ealiert hour of the first day and the latest hour of the last day.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jan 2022 12:33:06 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-the-min-and-max-value-for-each-date/m-p/2281602#M55832</guid>
      <dc:creator>icbd</dc:creator>
      <dc:date>2022-01-13T12:33:06Z</dc:date>
    </item>
    <item>
      <title>Re: Subtract the min and max value for each date</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-the-min-and-max-value-for-each-date/m-p/2287869#M56167</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="329747" data-lia-user-login="icbd" class="lia-mention lia-mention-user"&gt;icbd&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe you can try this code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="c"&gt;Measure =
VAR _1 =
    ADDCOLUMNS(
        'Table',
        "ifmin",
            IF(
                [Hours]
                    = CALCULATE(
                        MIN( 'Table'[Hours] ),
                        FILTER( 'Table', 'Table'[Date] = EARLIER( 'Table'[Date] ) )
                    ),
                1,
                0
            )
    )
RETURN
    SUMX( FILTER( _1, [ifmin] = 0 ), [Hours] )
        - SUMX( FILTER( _1, [ifmin] = 1 ), [Hours] )
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;result:&lt;/P&gt;
&lt;P&gt;&lt;img /&gt;&lt;/P&gt;
&lt;P&gt;Pbix in the end you can refer.&lt;/P&gt;
&lt;P&gt;2 please share some data without sensitive data about your&lt;SPAN&gt;&amp;nbsp;second thing,&amp;nbsp;ShiftId. And expect result.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;
&lt;P&gt;Community Support Team _ chenwu zhu&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 02:35:56 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-the-min-and-max-value-for-each-date/m-p/2287869#M56167</guid>
      <dc:creator>v-chenwuz-msft</dc:creator>
      <dc:date>2022-01-18T02:35:56Z</dc:date>
    </item>
    <item>
      <title>Re: Subtract the min and max value for each date</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-the-min-and-max-value-for-each-date/m-p/2289385#M56223</link>
      <description>&lt;P&gt;Hi v-chenwuz-msft, this gets me close, but it seems to ignore my current date filter and is calculating the entire table, thank you for the help so far!&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 16:39:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-the-min-and-max-value-for-each-date/m-p/2289385#M56223</guid>
      <dc:creator>icbd</dc:creator>
      <dc:date>2022-01-18T16:39:11Z</dc:date>
    </item>
    <item>
      <title>Re: Subtract the min and max value for each date</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-the-min-and-max-value-for-each-date/m-p/2292838#M56424</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="329747" data-lia-user-login="icbd" class="lia-mention lia-mention-user"&gt;icbd&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;You can try to add filter() to replace&amp;nbsp;the "table" which is the first parameter&amp;nbsp;of ADDCOLUMNS(). Or maybe the relationship between data table and date table limits the current date filter.&lt;/P&gt;
&lt;P&gt;Please share your pbix file without sensitive data, if you need more help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best Regards&lt;/P&gt;
&lt;P&gt;Community Support Team _ chenwu zhu&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 08:00:32 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-the-min-and-max-value-for-each-date/m-p/2292838#M56424</guid>
      <dc:creator>v-chenwuz-msft</dc:creator>
      <dc:date>2022-01-20T08:00:32Z</dc:date>
    </item>
    <item>
      <title>Re: Subtract the min and max value for each date</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-the-min-and-max-value-for-each-date/m-p/2294423#M56515</link>
      <description>&lt;P&gt;That did not work, but I think I now know why. I cannot upload the pbix as everything is direct queries so you'd have no data to work with.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The reason this does not work is that I have multiple hours in the same day, for example:&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;Date&lt;/TD&gt;&lt;TD&gt;&amp;nbsp; &amp;nbsp;Hours&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2022-01-20&lt;/TD&gt;&lt;TD&gt;&amp;nbsp; &amp;nbsp;7.25&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2022-01-20&lt;/TD&gt;&lt;TD&gt;&amp;nbsp; &amp;nbsp;8.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2022-01-20&lt;/TD&gt;&lt;TD&gt;&amp;nbsp; &amp;nbsp;10.37&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2022-01-20&lt;/TD&gt;&lt;TD&gt;&amp;nbsp; &amp;nbsp;15.00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2022-01-20&lt;/TD&gt;&lt;TD&gt;&amp;nbsp; &amp;nbsp;23.25&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2022-01-21&lt;/TD&gt;&lt;TD&gt;&amp;nbsp; &amp;nbsp;8.18&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2022-01-21&lt;/TD&gt;&lt;TD&gt;&amp;nbsp; &amp;nbsp;9.45&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2022-01-21&lt;/TD&gt;&lt;TD&gt;&amp;nbsp; &amp;nbsp;11.77&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2022-01-21&lt;/TD&gt;&lt;TD&gt;&amp;nbsp; &amp;nbsp;23.22&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In this particular case, say I am filtering the data to see those two days, the calculation I want Power BI to do would be the last value of 2022-01-20 minus the first value of 2022-01-20, and the same for 2022-01-21.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This would give me: 23.25 - 7.25 + 23.22 - 8.18 = 31.04&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The measure you gave me unfortunately sums the whole thing and gives me numbers in the millions as there are roughly 4000 entries per hour in my database.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate the help you have given so far, I'm quite new to this.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Jan 2022 23:18:36 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Subtract-the-min-and-max-value-for-each-date/m-p/2294423#M56515</guid>
      <dc:creator>icbd</dc:creator>
      <dc:date>2022-01-20T23:18:36Z</dc:date>
    </item>
  </channel>
</rss>

