cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
joshcomputer1
Helper V
Helper V

Count between start and end date

I have a table as follows.  I want to get a count of names between start and end date.  the result is a table like figure 2.  I have a datetable related to this table. When I do the measure, it is just giving me a count based on start date.  So, if I have two that started on 1.3 then it shows a 2. Which is not what I want. 

 

The Measure I tried is this:

TEST NEW Headcount = calculate(
                                           count(TEST[Name]),
                                           Filter (
                                           TEST,
                                          TEST[Start_Date] <= calculate(max(datetable1[date]) ) &&
                                          TEST[End_Date] >= calculate(min(DateTable1[Date]))))

 

 

Name              Start_Date                                       End_Date

AbbyTuesday, January 1, 2019Thursday, January 3, 2019
BillWednesday, January 2, 2019Wednesday, January 2, 2019
ChrisThursday, January 3, 2019Saturday, January 5, 2019
DaveThursday, January 3, 2019Friday, January 4, 2019
ElliotFriday, January 4, 2019Wednesday, January 9, 2019
FrankSaturday, January 5, 2019Monday, January 7, 2019

 

DESIRED RESULT SET

DateEmployee Count
1/1/20191
1/2/20192
1/3/20193
1/4/20193
1/5/20193
1/6/20192
1/7/20192
1/8/20191
1/9/20191
1 ACCEPTED SOLUTION
MFelix
Super User
Super User

Hi @joshcomputer1 ,

 

Your measure is correct however your datetable needs to be disconnected from your Test Table.

 

Since you have a relationship on the Start Date your data is filtered by the start date only so give you 6  as a result and not the expect outcome.

 

Check the image below and PBIX file attach:

Start_end_date.gif

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



View solution in original post

2 REPLIES 2
MFelix
Super User
Super User

Hi @joshcomputer1 ,

 

Your measure is correct however your datetable needs to be disconnected from your Test Table.

 

Since you have a relationship on the Start Date your data is filtered by the start date only so give you 6  as a result and not the expect outcome.

 

Check the image below and PBIX file attach:

Start_end_date.gif

 

Regards,

MFelix


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Anonymous
Not applicable

here is my suggestion to tackle this :

 

first Make a new date table.

 

DateTable = Calendar(Minx(table1,Table1[Date]),Now()) 

Now add a new calculated column:

 

DateSlicer = CALCULATE(
    COUNTROWS(contractid),
    FILTER(Table1,
        DateTable[Date] >= [startdate] &&
        DateTable[Date] <= [Enddate])

 

Hope this  will help.

Helpful resources

Announcements
August 1 episode 9_no_dates 768x460.jpg

The Power BI Community Show

Watch the playback when Priya Sathy and Charles Webb discuss Datamarts! Kelly also shares Power BI Community updates.

Power BI Dev Camp Session 24 without aka link and time 768x460.jpg

Ted's Dev Camp - July 28, 2022

Watch Session 24 of Ted's Dev Camp along with past sessions!

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Top Solution Authors
Top Kudoed Authors