<?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: Count total rows within given time range in a given date range in DAX Commands and Tips</title>
    <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2496424#M68892</link>
    <description>&lt;P&gt;It works! Thank you! Also lots of thanks for all the replies under this post.&lt;/P&gt;</description>
    <pubDate>Thu, 05 May 2022 15:18:43 GMT</pubDate>
    <dc:creator>Jacob_Li</dc:creator>
    <dc:date>2022-05-05T15:18:43Z</dc:date>
    <item>
      <title>Count total rows within given time range in a given date range</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2494153#M68769</link>
      <description>&lt;P&gt;I am working on a measure to get the total headcounts of customers within a given time range. But I need to consider two time ranges:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;The active period of the customer (StartDate &amp;amp; EndDate)&lt;/LI&gt;&lt;LI&gt;The time period we are interested in&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;As can be seen on the screenshot above, I want to calculate the total headcounts within the date range 2022-05-03 to 2022-05-04.&lt;/P&gt;&lt;P&gt;Since it only includes two days, the calculation is pretty straightfoward: on day 1 we have Customer 5 and Customer 6 meeting the criteria, on day 2 we still have these two customers active. Thus the results should be: 2+2=4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Based on the idea of v-yingjl&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.powerbi.com/t5/Power-Query/Count-rows-if-between-two-time-slots/td-p/1424481" target="_blank"&gt;https://community.powerbi.com/t5/Power-Query/Count-rows-if-between-two-time-slots/td-p/1424481&lt;/A&gt; and other posts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote the measure as follows:&lt;/P&gt;&lt;P&gt;Headcounts=&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;calendardate&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;max&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'Calendar'[Date]&lt;/SPAN&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;num_ava&lt;/SPAN&gt;&lt;SPAN&gt;=&lt;/SPAN&gt;&lt;SPAN&gt;calculate&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;countrows&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;filter&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;all&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'fact'&lt;/SPAN&gt;&lt;SPAN&gt;),&lt;/SPAN&gt;&lt;SPAN&gt;calendardate&lt;/SPAN&gt;&lt;SPAN&gt;&amp;gt;='fact&lt;/SPAN&gt;&lt;SPAN&gt;'[StartDate]&lt;/SPAN&gt;&lt;SPAN&gt; &amp;amp;&amp;amp; &lt;/SPAN&gt;&lt;SPAN&gt;calendardate&lt;/SPAN&gt;&lt;SPAN&gt;&amp;lt;=&lt;/SPAN&gt;&lt;SPAN&gt;'fact'[EndDate]&lt;/SPAN&gt;&lt;SPAN&gt;)))&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I am wondering how could I get the total headcounts based on the measure. Any thoughts and ideas are appreciated.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Wed, 04 May 2022 18:15:26 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2494153#M68769</guid>
      <dc:creator>Jacob_Li</dc:creator>
      <dc:date>2022-05-04T18:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: Count total rows within given time range in a given date range</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2494230#M68774</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="338319" data-lia-user-login="Jacob_Li" class="lia-mention lia-mention-user"&gt;Jacob_Li&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Check if it does helps or not?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Count customer = 
Var _Mindate = DATEVALUE( "3/5/2022")
Var _Maxdate = DATEVALUE( "4/5/2022")

Var _Count = CALCULATE(COUNTROWS('Customer Count'),'Customer Count'[Start Date]&amp;gt;=_Mindate,'Customer Count'[End Date]&amp;lt;=_Maxdate)
return _Count&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Arul&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 19:19:51 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2494230#M68774</guid>
      <dc:creator>Arul</dc:creator>
      <dc:date>2022-05-04T19:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: Count total rows within given time range in a given date range</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2494275#M68775</link>
      <description>&lt;P&gt;Thank you, but I am afraid the restriction might be correct. Because I want to evaluate each individual date between 05/03/2022 and 05/04/2022, I need to compare these two dates with start date and end date for twice, instead of comparing 05/03/2022 with StartDate and 05/04/2022 with EndDate.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks anyway.&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 19:37:33 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2494275#M68775</guid>
      <dc:creator>Jacob_Li</dc:creator>
      <dc:date>2022-05-04T19:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: Count total rows within given time range in a given date range</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2494299#M68776</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="338319" data-lia-user-login="Jacob_Li" class="lia-mention lia-mention-user"&gt;Jacob_Li&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;assuming no relationships invloved, you may try&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Headcounts =
VAR SelectedDates =
    VALUES ( 'Calendar'[Date] )
RETURN
    SUMX (
        'fact',
        VAR ActiveDates =
            CALENDAR ( 'fact'[StartDate], 'fact'[EndDate] )
        RETURN
            IF ( COUNTROWS ( INTERSECT ( SelectedDates, ActiveDates ) ) &amp;gt; 0, 1, 0 )
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 19:58:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2494299#M68776</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-05-04T19:58:45Z</dc:date>
    </item>
    <item>
      <title>Re: Count total rows within given time range in a given date range</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2495121#M68800</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Please check the below picture and the attached pbix file.&lt;/P&gt;
&lt;P&gt;I tried to create a sample pbix file like below in order to simplify the sample.&lt;/P&gt;
&lt;P&gt;I suggest having a calendar table as a dimension table.&lt;/P&gt;
&lt;P&gt;I hope the below measure can help to have an idea to create a similar measure and apply it to your data model.&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;LI-CODE lang="markup"&gt;Customers count measure: =
COUNTROWS (
    FILTER (
        Data,
        Data[StartDate] &amp;lt;= MAX ( 'Calendar'[Date] )
            &amp;amp;&amp;amp; Data[EndDate] &amp;gt;= MIN ( 'Calendar'[Date] )
    )
)
&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 05 May 2022 06:49:04 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2495121#M68800</guid>
      <dc:creator>Jihwan_Kim</dc:creator>
      <dc:date>2022-05-05T06:49:04Z</dc:date>
    </item>
    <item>
      <title>Re: Count total rows within given time range in a given date range</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2496253#M68881</link>
      <description>&lt;P&gt;Thanks for your reply. I took a screenshot from your pbix file.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;As you could see, two dates are selected: 2022/12/30 and 2022/12/31, is there any way that I could get the value of 2, which is the sum of the column of the calculated measure (1+1)?&lt;/P&gt;</description>
      <pubDate>Thu, 05 May 2022 14:02:45 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2496253#M68881</guid>
      <dc:creator>Jacob_Li</dc:creator>
      <dc:date>2022-05-05T14:02:45Z</dc:date>
    </item>
    <item>
      <title>Re: Count total rows within given time range in a given date range</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2496279#M68883</link>
      <description>&lt;P&gt;Thank you for your reply. Is there any way that I could get the sum of the "column" of headcounts measure from the table visual below. I am pretty sure I am very close to it.&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 05 May 2022 14:10:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2496279#M68883</guid>
      <dc:creator>Jacob_Li</dc:creator>
      <dc:date>2022-05-05T14:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: Count total rows within given time range in a given date range</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2496329#M68885</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="338319" data-lia-user-login="Jacob_Li" class="lia-mention lia-mention-user"&gt;Jacob_Li&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Try&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Headcounts =
SUMX (
    CROSSJOIN ( VALUES ( 'Calendar'[Date] ), VALUES ( 'fact'[StartDate] ) ),
    CALCULATE (
        VAR SelectedDates =
            VALUES ( 'Calendar'[Date] )
        VAR ActiveDates =
            CALENDAR ( 'fact'[StartDate], 'fact'[EndDate] )
        RETURN
            IF ( COUNTROWS ( INTERSECT ( SelectedDates, ActiveDates ) ) &amp;gt; 0, 1, 0 )
    )
)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 05 May 2022 14:24:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2496329#M68885</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-05-05T14:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: Count total rows within given time range in a given date range</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2496402#M68890</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="317289" data-lia-user-login="tamerj1" class="lia-mention lia-mention-user"&gt;tamerj1&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;By calendar('fact'[StartDate],'fact'[EndDate]), do you mean by&amp;nbsp;CALENDAR (calculate(max('data'[startdate]),allexcept('data','Data'[Customer])) , calculate(max('data'[EndDate]),allexcept('data','Data'[Customer])) )? Because otherwise this measure is not working properly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By replacing the underlined part, the measure is written as follows&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;Headcounts =
SUMX (
    CROSSJOIN ( VALUES ( 'Calendar'[Date] ), VALUES ( 'fact'[StartDate] ) ),
    CALCULATE (
        VAR SelectedDates =
            VALUES ( 'Calendar'[Date] )
        VAR ActiveDates =
            CALENDAR (calculate(max('data'[startdate]),allexcept('data','Data'[Customer])) , calculate(max('data'[EndDate]),allexcept('data','Data'[Customer])) )
        RETURN
            IF ( COUNTROWS ( INTERSECT ( SelectedDates, ActiveDates ) ) &amp;gt; 0, 1, 0 )
    )
)&lt;/LI-CODE&gt;&lt;P&gt;However, the result is not as expected.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;img /&gt;&lt;/P&gt;&lt;P&gt;It gives the total 12 instead of 2.&lt;/P&gt;</description>
      <pubDate>Thu, 05 May 2022 15:04:47 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2496402#M68890</guid>
      <dc:creator>Jacob_Li</dc:creator>
      <dc:date>2022-05-05T15:04:47Z</dc:date>
    </item>
    <item>
      <title>Re: Count total rows within given time range in a given date range</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2496409#M68891</link>
      <description>&lt;P&gt;&lt;a href="javascript:void(0)" data-lia-user-mentions="" data-lia-user-uid="338319" data-lia-user-login="Jacob_Li" class="lia-mention lia-mention-user"&gt;Jacob_Li&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code wat not correct. Sorry I'm typing on the phone&lt;/P&gt;&lt;P&gt;try this one&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;Headcounts =
SUMX (
    CROSSJOIN ( VALUES ( 'Calendar'[Date] ), VALUES ( 'fact'[StartDate] ) ),
    CALCULATE (
        VAR SelectedDates =
            VALUES ( 'Calendar'[Date] )
        RETURN
            SUMX (
                'fact',
                VAR ActiveDates =
                    CALENDAR ( 'fact'[StartDate], 'fact'[EndDate] )
                RETURN
                    IF ( COUNTROWS ( INTERSECT ( SelectedDates, ActiveDates ) ) &amp;gt; 0, 1, 0 )
            )
    )
)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 05 May 2022 15:11:12 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2496409#M68891</guid>
      <dc:creator>tamerj1</dc:creator>
      <dc:date>2022-05-05T15:11:12Z</dc:date>
    </item>
    <item>
      <title>Re: Count total rows within given time range in a given date range</title>
      <link>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2496424#M68892</link>
      <description>&lt;P&gt;It works! Thank you! Also lots of thanks for all the replies under this post.&lt;/P&gt;</description>
      <pubDate>Thu, 05 May 2022 15:18:43 GMT</pubDate>
      <guid>https://community.fabric.microsoft.com/t5/DAX-Commands-and-Tips/Count-total-rows-within-given-time-range-in-a-given-date-range/m-p/2496424#M68892</guid>
      <dc:creator>Jacob_Li</dc:creator>
      <dc:date>2022-05-05T15:18:43Z</dc:date>
    </item>
  </channel>
</rss>

