<?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 Calculating the Sum of Active Units Between Two Dates in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-Sum-of-Active-Units-Between-Two-Dates/m-p/1639734#M33286</link>
    <description>&lt;P&gt;*Deleted from Desktop Discussion*&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello, I am attempting to calculate the number of units which were active between the selected dates on a slicer. Each Unit has a "DATE_IN_SERVICE" and a "DATE_OUT_SERVICE" column.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From, following this solution (&lt;A href="https://community.powerbi.com/t5/Desktop/Use-date-slicer-to-check-if-date-falls-between-two-dates/m-p/446810" target="_blank" rel="noopener"&gt;https://community.powerbi.com/t5/Desktop/Use-date-slicer-to-check-if-date-falls-between-two-dates/m-p/446810&lt;/A&gt;) My current DAX is the following (I am hung up on using MIN/MAX however, and think this may be the reason I'm not getting the expected results):&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Power_Unit_Count =&lt;BR /&gt;VAR SelectedDate = SELECTEDVALUE(DIM_DATE[date_date])&lt;/P&gt;&lt;P&gt;RETURN&lt;BR /&gt;IF(SelectedDate &amp;gt;= MIN(DIM_PUNIT_CUSTOM[DATE_IN_SERVICE]) &amp;amp;&amp;amp; SelectedDate &amp;lt;= MAX(DIM_PUNIT_CUSTOM[DATE_OUT_SERVICE]),DISTINCTCOUNT(DIM_PUNIT_CUSTOM[UNIT_ID]),0)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example of current Data structure&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;Expected Result is 112 total, by following the logic below:&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;Filtering for Units which have a non-blank DATE IN SERVICE and DATE_OUT_SERVICE is either BLANK or Greater than the last date in the slicer.&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;&lt;P&gt;&amp;nbsp;&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>Tue, 02 Feb 2021 17:42:11 GMT</pubDate>
    <dc:creator>gsd217</dc:creator>
    <dc:date>2021-02-02T17:42:11Z</dc:date>
    <item>
      <title>Calculating the Sum of Active Units Between Two Dates</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-Sum-of-Active-Units-Between-Two-Dates/m-p/1639734#M33286</link>
      <description>&lt;P&gt;*Deleted from Desktop Discussion*&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello, I am attempting to calculate the number of units which were active between the selected dates on a slicer. Each Unit has a "DATE_IN_SERVICE" and a "DATE_OUT_SERVICE" column.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From, following this solution (&lt;A href="https://community.powerbi.com/t5/Desktop/Use-date-slicer-to-check-if-date-falls-between-two-dates/m-p/446810" target="_blank" rel="noopener"&gt;https://community.powerbi.com/t5/Desktop/Use-date-slicer-to-check-if-date-falls-between-two-dates/m-p/446810&lt;/A&gt;) My current DAX is the following (I am hung up on using MIN/MAX however, and think this may be the reason I'm not getting the expected results):&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Power_Unit_Count =&lt;BR /&gt;VAR SelectedDate = SELECTEDVALUE(DIM_DATE[date_date])&lt;/P&gt;&lt;P&gt;RETURN&lt;BR /&gt;IF(SelectedDate &amp;gt;= MIN(DIM_PUNIT_CUSTOM[DATE_IN_SERVICE]) &amp;amp;&amp;amp; SelectedDate &amp;lt;= MAX(DIM_PUNIT_CUSTOM[DATE_OUT_SERVICE]),DISTINCTCOUNT(DIM_PUNIT_CUSTOM[UNIT_ID]),0)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example of current Data structure&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;Expected Result is 112 total, by following the logic below:&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;Filtering for Units which have a non-blank DATE IN SERVICE and DATE_OUT_SERVICE is either BLANK or Greater than the last date in the slicer.&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;&lt;P&gt;&amp;nbsp;&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>Tue, 02 Feb 2021 17:42:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-Sum-of-Active-Units-Between-Two-Dates/m-p/1639734#M33286</guid>
      <dc:creator>gsd217</dc:creator>
      <dc:date>2021-02-02T17:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating the Sum of Active Units Between Two Dates</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-Sum-of-Active-Units-Between-Two-Dates/m-p/1639852#M33287</link>
      <description>&lt;P&gt;Hi!&lt;BR /&gt;&lt;BR /&gt;I'd transform the date ranges into single dates. Ie in power query (if the time values are not important) change start and end into dates, then change them into integers, create a custom column Date = {[start]..[end]} and after that you should be able to extract the Date lists as separate rows. Now you can just plug in a relationship from you calendar table date to that Date and count id's or whatever for values.&lt;BR /&gt;&lt;BR /&gt;Edit: oh yeah I think your method should work too. Try putting that&amp;nbsp;&lt;SPAN&gt;SELECTEDVALUE(DIM_DATE[date_date]) on a card or something and see what happens. Maybe something like this could work, can't test right now:&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Power_Unit_Count =
VAR _start = MIN( SELECTEDVALUES(DIM_DATE[date_date]) )
VAR _end = MAX( SELECTEDVALUES(DIM_DATE[date_date]) )
RETURN
calculate(
    DISTINCTCOUNT(DIM_PUNIT_CUSTOM[UNIT_ID],
    DIM_PUNIT_CUSTOM[DATE_IN_SERVICE] &amp;gt;= _start,
    DIM_PUNIT_CUSTOM[DATE_OUT_SERVICE] &amp;lt;= _end
)
&lt;/LI-CODE&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 19:09:11 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-Sum-of-Active-Units-Between-Two-Dates/m-p/1639852#M33287</guid>
      <dc:creator>Gabriel_Walkman</dc:creator>
      <dc:date>2021-02-02T19:09:11Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating the Sum of Active Units Between Two Dates</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-Sum-of-Active-Units-Between-Two-Dates/m-p/1640412#M33309</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="268710" data-lia-user-login="Gabriel_Walkman" class="lia-mention lia-mention-user"&gt;Gabriel_Walkman&lt;/a&gt;&amp;nbsp; Thanks! For the most part it worked. I did have to make some modifications to suit my needs.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;PUnit_Count = 
VAR _start = FIRSTDATE(DIM_DATE[date_date])
VAR _end = LASTDATE(DIM_DATE[date_date])
RETURN
calculate(
    DISTINCTCOUNT(DIM_PUNIT_CUSTOM[UNIT_ID]),
    DIM_PUNIT_CUSTOM[DATE_IN_SERVICE] &amp;lt;= _end,
    DIM_PUNIT_CUSTOM[DATE_OUT_SERVICE] &amp;gt;= _end || ISBLANK(DIM_PUNIT_CUSTOM[DATE_OUT_SERVICE]),
   NOT(ISBLANK(DIM_PUNIT_CUSTOM[DATE_IN_SERVICE]))
)&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 03 Feb 2021 01:31:54 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Calculating-the-Sum-of-Active-Units-Between-Two-Dates/m-p/1640412#M33309</guid>
      <dc:creator>gsd217</dc:creator>
      <dc:date>2021-02-03T01:31:54Z</dc:date>
    </item>
  </channel>
</rss>

