Forum Discussion
Get count between start and end date
- 4 years ago
hnazzal Okay then you can try like below or you can share your PBIX file after removing sensitive data:-
_Attendees = var start_date = min(calender[date]) var end_date = max(calender[date]) return SUMX ( FILTER ( 'Table (6)', OR ( ( MONTH ( 'Table (6)'[Start Date] ) = month(start_date) && YEAR ( 'Table (6)'[Start Date] ) = year(start_date) ), ( MONTH ( 'Table (6)'[End Date] ) = month(end_date) && YEAR ( 'Table (6)'[End Date] ) = year(end_date) ) ) ), [Attendees count] ) - 4 years ago
Thank you, i will try this code
But what do you mean by
[Attendees count]
Thank you for your reply!
Let me explain my case exactly
| Project | Start Date | End Date | Attendees count |
| P1 | 1/12/2021 | 1/5/2022 | 10 |
| P2 | 5/5/2021 | 12/12/2021 | 7 |
| P3 | 12/7/2021 | 12/29/2021 | 3 |
| P4 | 6/6/2021 | 8/20/2021 | 6 |
| P5 | 12/5/2021 | 3/3/2021 | 4 |
So, I need to calculate the count of attendees for the project either start with December 2021 OR End in December 2021
which in example 7 + 3 + 4 because these projects either start or end in December
I create a measure as follows:
TEST NEW Headcount = calculate(Sum(TEST[Name]),
Filter (
TEST,
TEST[Start_Date] <= calculate(max('calendar'[Date] )) &&
Test[End_Date] >= calculate(min('calendar'[Date]))))
But still, it gives me the wrong dates.
Thank you very much.
hnazzal , You can use below code:-
_Attendees =
SUMX (
FILTER (
'Table (6)',
OR (
(
MONTH ( 'Table (6)'[Start Date] ) = 12
&& YEAR ( 'Table (6)'[Start Date] ) = 2021
),
(
MONTH ( 'Table (6)'[End Date] ) = 12
&& YEAR ( 'Table (6)'[End Date] ) = 2021
)
)
),
[Attendees count]
)
Output:-
- hnazzal4 years agoNew Member
I tried this code, but unfortunately, it doesn't work
BTW, the start date and end date will be dynamic, I mean to be in the slicer to allow users to pick the start and end date.
I created a calendar date to be user bu again it doesn't works with me 😞
Thank you,
- Samarth_184 years agoCommunity Champion
hnazzal Okay then you can try like below or you can share your PBIX file after removing sensitive data:-
_Attendees = var start_date = min(calender[date]) var end_date = max(calender[date]) return SUMX ( FILTER ( 'Table (6)', OR ( ( MONTH ( 'Table (6)'[Start Date] ) = month(start_date) && YEAR ( 'Table (6)'[Start Date] ) = year(start_date) ), ( MONTH ( 'Table (6)'[End Date] ) = month(end_date) && YEAR ( 'Table (6)'[End Date] ) = year(end_date) ) ) ), [Attendees count] )- hnazzal4 years agoNew Member
Thank you, i will try this code
But what do you mean by
[Attendees count]