I'm still new to PowerPivot and tabular models and it's hard work switching from relational DBs.
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.
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.
Logbook Table:
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
This is my best attempt…
Cumulated Logged Days:
=CALCULATE(
COUNTROWS('Calendar'),
FILTER(
ALL(Logbook),
COUNTROWS(
FILTER(
Logbook,
EARLIER(Logbook[Vehicle ID]) = [Vehicle ID]
&& EARLIER(Logbook[Row ID]) <= [Row ID]
)
)
),
FILTER(
ALL('Calendar'),
'Calendar'[Date] >= MIN(Logbook[Start Date])
&& 'Calendar'[Date] <= MAX(Logbook[End Date])
)
)