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
Kepler1571
Regular Visitor

Counting active days between start and end date and slicer min max dates

Hi All, I have been stuck on this issue for way too long so reaching out for some support. 

 

I have a table that shows a client's name, location, start date and end date. 

Between the clients start and end date they client will be considered as active. 

 

I need to build a report that calculates the number of days a client is active (datediff) but it also needs to be responsive to a minimum and maximum date range as selected by a slicer. E.g a client active from 01/01/2022 to 31/12/22. Slicer selected equals 01/08/2022 to 31/08/2022 therefore the result should be that the client is active for 31 days between that date range. and then sum of all clients to get total number of active days for all clients. 

 

i have my slicer run by dates in a date table and through several attemps have got the closest with the following custom measure below. 

 

In this case when i place the measure in a table i get the correct result for each individual client. However the total is not adding up the result for each individual client rather it is producing a result based on the minimum and maximum dates as set in the slicer. image attached should show total 30. Any help would be greatly appreciated. 

 

 

 

 

 

 

Bed night count = 
VAR MinDate = MIN('Dates'[Date])

VAR MaxDate = MAX('Dates'[Date])

VAR MinCalcDate = IF(SELECTEDVALUE('Client living arrangements'[Start Date]) <= MinDate, MinDate, IF(SELECTEDVALUE('Client living arrangements'[Start Date]) > MaxDate, BLANK(), SELECTEDVALUE('Client living arrangements'[Start Date])))

VAR MaxCalcDate = IF(SELECTEDVALUE('Client living arrangements'[End Date])>= MaxDate || SELECTEDVALUE('Client living arrangements'[End Date]) = BLANK(), MaxDate, IF(SELECTEDVALUE('Client living arrangements'[End Date])<MinDate, BLANK(), SELECTEDVALUE('Client living arrangements'[End Date])))

RETURN

DATEDIFF(MinCalcDate,MaxCalcDate,DAY)

 

 

 

 

 

 Capture.PNG

1 ACCEPTED SOLUTION

See the transformation steps in the Query Editor.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

13 REPLIES 13
srutiR2403
Frequent Visitor

Hi Kepler

I am also stuck in calculating sum of the active days can you please post the steps how u achieved it.

amitchandak
Super User
Super User

@Kepler1571 , Try a measure like

 

New measure =
var _max = maxx(allselected(Date),Date[Date])
var _min = minx(allselected(Date),Date[Date])
return
Sumx(Table, max([Start Date], _min ), min([End Date],_max), Day)

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

Hi, when trying this i get the error below:

New measure =
var _max = maxx(allselected(Dates),Dates[Date])
var _min = minx(allselected(Dates),Dates[Date])
return
Sumx('Client living arrangements', max([Start Date], _min), min('Client living arrangements'[End Date],_max),Day)


Too many arguments were passed to the SUMX function. The maximum argument count for the function is 2.

Ashish_Mathur
Super User
Super User

Hi,

Share data in a fornat that can be pasted in an MS Excel file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

here is some sample data 

 

clientStatusNameStart DateEnd Date
35207Inactivehouse 112/12/2021 0:00 
53840Activehouse 221/12/2020 0:0028/01/2021 0:00
53840Activehouse 228/01/2021 0:0012/02/2021 0:00
53840Activehouse 312/02/2021 0:0012/10/2022 0:00
53840Activehouse 412/10/2022 0:00 
53840Activehouse 129/10/2020 0:0021/12/2020 0:00
53841Activehouse 47/02/2023 0:00 
53841Activehouse 626/03/2021 0:0016/12/2021 0:00
53841Activehouse 315/09/2020 0:0026/03/2021 0:00

Hi,

Please find attached the PBi file.

Hope this helps.

Ashish_Mathur_0-1694519441849.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hello, 

 

This just counts the active clients. I'm trying to calculate days that each client is active for and then the sum of all the active days.

Hi,

Writ this measure

=Active days = CALCULATE(COUNTROWS(Data),Data[Status]="Active")

Hope this helps.

Ashish_Mathur_0-1694572332009.png

 


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

ok i see what you've done now, you have created an entry for every date for every client and marked if they are active on that day or not. How did you do this? The sample i sent only has three clients but my actual data set has 100s and more coming every day? Is there a way to automate this? 

See the transformation steps in the Query Editor.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Hi Ashish

 

I have similar requirement but little different

srutiR2403_0-1720619425069.png

In this example i could create measures for duration and active days.But I could not sum the active days. In the above example 820/365=2.245. I cannot get the value of 820. 365 comes from the date slicer that we can calculate.

For duration i added a column in the table and did datediff.

For active days i creasted a measure and i could get the activedays count for each pol.but For summing up of the active days i am not sure how to achieve.

 

Hi,

I am clueless about that you want.  Start a new thread, explain the question and show the expected result there.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Thank you ashish for replying. I have completed this sissue

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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