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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Help with formula counting by dates

Hello, 

 

I posted an earlier problem of counting clients based on whether they started a project or they had a project interaction based on different date ranges. 

 

Someone solved it with the following formula which i think is correct and has been working. 

 

 

Total clients by start date or casenote =
VAR _Start = FIRSTDATE(Calender[Date])
VAR _End = LASTDATE(Calender[Date])
VAR _Clients =
CALCULATETABLE(
VALUES('All projects'[Client Record ID]),
'All projects'[Project Start Date] >= _Start,
'All projects'[Project Start Date] <= _End)
VAR _CLientNotes =
CALCULATETABLE(
VALUES('All projects'[Client Record ID]),
'All Casenotes'[Date of Session] >= _Start,
'All Casenotes'[Date of Session] <= _End,
CROSSFILTER('All projects'[Project Record ID],'All Casenotes'[Project Record ID],Both))
RETURN
COUNTROWS ( DISTINCT ( UNION ( _Clients, _CLientNotes )))
 
However, I noticed today that this has been counting clients that do not fit into the date criteria. For example. The date range in the below is 01/04/2019 - 31/03/2020, but as you can see the forumla is counting clients that do not fit into this range. 
 
Client counting error.PNG

 

Not sure what is wrong here? I changed the date settings in the load to use Locale (UK) but didn't change anything. There are no links between the calandar table and anything else so i don't think filtering is a problem either?
 
Any suggestions on what's wrong would be very welcome!
 
Thanks 
 
 
5 REPLIES 5
Icey
Community Support
Community Support

Hi @Anonymous ,

 

Is this problem solved?

 

If it is solved, please always accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.

 

If not, please let me know.

 

 

Best Regards,

Icey

Anonymous
Not applicable

Hi Icey, 

 

Unfortunately i'm still struggling with this. I'm checking it by pulling in project name and start date from the all projects table, and casenotes session date from the all casenotes table and then finally the measure. 

 

I'm then filtering with the calander table and it still seems to be counting casenotes that are outside the filtered range. 

 

Any suggestions?

 

Thanks 

Icey
Community Support
Community Support

Hi @Anonymous ,

 


 

Not sure what is wrong here? I changed the date settings in the load to use Locale (UK) but didn't change anything. There are no links between the calandar table and anything else so i don't think filtering is a problem either?
 

datetable.PNG

There is no relationship between 'Date's table and "All Casenotes" table. So 'Dates'[Date] slicer will not filter 'All Casenotes'[Date of Session].

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , Can share the logic. Can you share sample data and sample output in table format?

 

refer if this can he any help : https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-trend/ba-p/882970

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi 

 

Here is the original topic that this expression came from. 

 

https://community.powerbi.com/t5/Desktop/count-distinct-based-on-two-date-using-OR/m-p/1145546#M5198...

 

In terms of providing sample data. Do you mean to export some data from the three relevant tables (client / project / interaction) or would screen shots suffice?

 

Thanks 

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors