Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
elinevans
Helper I
Helper I

Distinct count of a column based on start and end dates

elinevans_0-1625236975134.png

Here is the data I'm using. Each client can have more than 1 service and I want to find clients active in a service within a time period (say between date x and date y) defined by a slicer on the report. The slicer is based off a date table created by using CALENDARAUTO(). So essentially I want to find how many clients have a start date before y AND end date after x. Where x and y can be altered by a date slicer.

 

I orignally tested it without a slicer:

No clients in date date = CALCULATE(DISTINCTCOUNT(Table1[Client ref]), FILTER(Table1, Table1[Start Date]<=date(2020,7,4) && Table1[End Date]>=date(2020,5,1)))
for dates between 1st May 2020 and 4th July 2020 and got the correct answer, which is 3. The clients in this case would be 1,4,5.
 
But when I tested it using the max/min dates of the slicer:
No clients in date wslice = CALCULATE(DISTINCTCOUNT(Table1[Client ref]), FILTER(Table1, (Table1[Start Date]<=max(Datetable[Date]) && Table1[End Date]>=min(Datetable[Date]))))
I get 5. Which is incorrect. 
 
I've tried it with different relationships between start/end date and date table but I just can't get it to work. 
 
Any help, or explaination as to why this isn't possible would be greatly appreciated!! 
 
Thanks
 
1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Picture2.png

 

 

https://www.dropbox.com/s/pmukzses4xazvig/elinevans.pbix?dl=0 

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

3 REPLIES 3
elinevans
Helper I
Helper I

If I then added another table

Client ref

 
1

Female

2Male
3Nonbinary
4Female

 and created a relationship between the client ref on the client table and service table and wanted to create a pi chart of the different genders, is there a formula to only include the genders of those who are active?

 

I'm currently doing 

genderfemale = CALCULATE(count(Client[Gender]),filter(Client, Client[Gender]="Female"), FILTER(ServiceInfo, ServiceInfo[StartDate] <= MAX(DateTable[Date]) && ServiceInfo[EndDate] >= MIN(DateTable[Date])))
 to get the active females which seems to work but it means I have to do it for every gender (and some other classifications).
 
Is there a way to do it in a more efficient way
elinevans
Helper I
Helper I

Thank you!!

Jihwan_Kim
Super User
Super User

Picture2.png

 

 

https://www.dropbox.com/s/pmukzses4xazvig/elinevans.pbix?dl=0 

 

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.