Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi,
I have a table with StartDate and EndDate. I need to count the number of occurances between the StartDate and EndDate on a calendar table along the lines of the below. Any help would be greatly appreciated.
StartDate | EndDate | CalendarDate | Count | |
01/12/2019 | 03/12/2019 | 01/12/2019 | 3 | |
01/12/2019 | 04/12/2019 | 02/12/2019 | 4 | |
01/12/2019 | 04/12/2019 | 03/12/2019 | 3 | |
02/12/2019 | 08/12/2019 | 04/12/2019 | 1 | |
05/12/2019 | 1 | |||
06/12/2019 | 1 | |||
07/12/2019 | 1 | |||
08/12/2019 | 0 |
Thanks
Solved! Go to Solution.
Hi @pedanticpad ,
Try this:
Count Column =
CALCULATE (
COUNTROWS ( 'Table' ) + 0,
FILTER (
'Table',
'Table'[StartDate] <= EARLIER ( 'Calendar'[Date] )
&& 'Table'[EndDate] > EARLIER ( 'Calendar'[Date] )
)
)
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi @pedanticpad ,
Try this:
Count Column =
CALCULATE (
COUNTROWS ( 'Table' ) + 0,
FILTER (
'Table',
'Table'[StartDate] <= EARLIER ( 'Calendar'[Date] )
&& 'Table'[EndDate] > EARLIER ( 'Calendar'[Date] )
)
)
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks so much! That works perfectly
Hi @pedanticpad ,
Try this:
1. Create relationships between the two tables.
2. Create a measure.
Count =
COUNT ( 'Table'[StartDate] )
+ CALCULATE (
COUNT ( 'Table'[EndDate] ),
USERELATIONSHIP ( 'Calendar'[Date], 'Table'[EndDate] )
) + 0
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks Icey, Is there any way to use that to create a table that I can add calculated columns to rather than a visual?
Also, is it possible to ammend your formula to pull in criteria?
Thanks for the reply. Those 2 solutions work to give me the number of days between the two dates, but not the number of instances between 2 dates.
What I need is to be able to say on each day of the year we had x occupancy by using the StartDate and EndDate.
If it makes it any easier I was able to achieve it in MS Access using the below;
SELECT Import_CalendarDate.CalendarDate, Count(ID) AS TotalOccupancy
FROM Import_CalendarDate LEFT JOIN RoomOccupancy ON (Import_CalendarDate.CalendarDate>=RoomOccupancy.StartDate) AND (Import_CalendarDate.CalendarDate<RoomOccupancy.EndDate)
WHERE Import_CalendarDate.CalendarDate<date()
GROUP BY CalendarDate
ORDER BY Import_CalendarDate.CalendarDate;
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
113 | |
100 | |
78 | |
76 | |
52 |
User | Count |
---|---|
146 | |
109 | |
106 | |
88 | |
61 |