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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Dunner2020
Post Prodigy
Post Prodigy

countrows return less row with Max() function

Hi there,

 

I have created a measure which calculates the working days between two dates and excludes public holidays. Here is the measure:

 

No of days between two events = 

 
Var start_date = MAX('Table'[startdate])
Var end_date = MAX('Table'[Enddate])
Var varDaycount =
CALCULATE( COUNTROWS(Dates),
FILTER(ALL(Dates), Dates[Date] >= start_date &&
Dates[Date] <=end_date &&
Dates[IsHoliday] = FALSE() &&
(Dates[Day Of Week Name] <> "Saturday" &&
Dates[Day Of Week Name] <> "Sunday")
)
)
Return
varDaycount
 
I have noticed that when startdate is "12/08/2020 12:00:00 PM" and enddate is "31/08/2020 8:34:00 AM", measure returns 13 days instead of 14 days (there is no public holidays between two dates). I started debugging the program. I created another debugging measure which looks like as follow:
 
Debug measure = 
Var end_date = DATEVALUE("31/08/2020 8:34:00 AM" )
Var start_date = DATEVALUE("12/08/2020 12:00:00 PM")
RETURN
Var varDaycount =
CALCULATE(COUNTROWS(Dates),
FILTER(ALL(Dates), Dates[Date] >= start_date &&
Dates[Date] <=end_date &&
Dates[IsHoliday] = FALSE() &&
(Dates[Day Of Week Name] <> "Saturday" &&
Dates[Day Of Week Name] <> "Sunday")
)
)
Return
varDaycount
 
Debugging measure returns 14 days. I am not sure where I am making the mistake. Any advice would be really appreciated.
The sample file can be downloaded from here 
1 ACCEPTED SOLUTION
sanalytics
Super User
Super User

@Dunner2020 

It seems that your No of days between two events is taking 1 day after your start date..
why cant you wrap the start date and end date with datevalue and see what you are getting??
I mean to say,

No of days between two events = 

 
Var start_date = Datevalue(MAX('Table'[startdate]))
Var end_date = Datevalue(MAX('Table'[Enddate]))
Var varDaycount =
CALCULATE( COUNTROWS(Dates),
FILTER(ALL(Dates), Dates[Date] >= start_date &&
Dates[Date] <=end_date &&
Dates[IsHoliday] = FALSE() &&
(Dates[Day Of Week Name] <> "Saturday" &&
Dates[Day Of Week Name] <> "Sunday")
)
)
Return
varDaycount

 

Check what happens and let us know..

Regards,

sanalytics

if it is your solution then please accept it as  solution and also please like

View solution in original post

1 REPLY 1
sanalytics
Super User
Super User

@Dunner2020 

It seems that your No of days between two events is taking 1 day after your start date..
why cant you wrap the start date and end date with datevalue and see what you are getting??
I mean to say,

No of days between two events = 

 
Var start_date = Datevalue(MAX('Table'[startdate]))
Var end_date = Datevalue(MAX('Table'[Enddate]))
Var varDaycount =
CALCULATE( COUNTROWS(Dates),
FILTER(ALL(Dates), Dates[Date] >= start_date &&
Dates[Date] <=end_date &&
Dates[IsHoliday] = FALSE() &&
(Dates[Day Of Week Name] <> "Saturday" &&
Dates[Day Of Week Name] <> "Sunday")
)
)
Return
varDaycount

 

Check what happens and let us know..

Regards,

sanalytics

if it is your solution then please accept it as  solution and also please like

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.