Cumulated count of distinct dates in date ranges using DAX
<p>I'm still new to PowerPivot and tabular models and it's hard work switching from relational DBs.</p>

<p>I have two tables in power pivot: Logbook and Calendar - they are not linked.  Logbook rows have date ranges specified using [Start Date] and [End Date] columns.  I have Logbook rows grouped by [Vehicle ID] and I've added a sequential [Row ID] for each of the [Vehicle ID] groups.</p>

<p>The Logbook date ranges overlap each other and I'm trying to write a measure that gives the cumulative count of distinct days in the date ranges.</p>

<p>Logbook Table:</p>

<pre><code>Vehicle ID  Row ID  Start Date   End Date      *Cumulated Logged Days (Expected Result)*
AAA         1       1 Jun 2016   1 June 2016   1
AAA         2       1 Jun 2016   5 June 2016   5
AAA         3       10 Jun 2016  10 June 2016  6
BBB         1       1 Jun 2016   1 June 2016   1
BBB         2       5 Jun 2016   5 June 2016   2
BBB         3       7 Jun 2016   7 June 2016   3
</code></pre>

<p>This is my best attempt…</p>

<pre><code>Cumulated Logged Days:
=CALCULATE(
    COUNTROWS('Calendar'),
    FILTER(
        ALL(Logbook),
        COUNTROWS(
            FILTER(
                Logbook,
                EARLIER(Logbook[Vehicle ID]) = [Vehicle ID]
                &amp;&amp; EARLIER(Logbook[Row ID]) &lt;= [Row ID]
            )
        )
    ),
    FILTER(
        ALL('Calendar'),
        'Calendar'[Date] &gt;= MIN(Logbook[Start Date])
        &amp;&amp; 'Calendar'[Date] &lt;= MAX(Logbook[End Date])
    )
)
</code></pre>