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

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

Reply
RachnaV
Helper I
Helper I

How to get correct count of number of days till today

I need to create a measure Average Discharges per Day, its formula is Total Discharges at any point in time date divided by number of days in that point in time. 

But I am not getting the correct results due to incorrect denominator.

 

For eg. If I want to see the discharges in Calendar Year 2021 and upto today i.e. 9 Feb the calculation would be Total Discharges till 09-Feb-21 divided by 40(31 [days in Jan] + 9[days in Feb]). But whatever calculation I use, ends up counting 28 days for Feb in the denominator, which becomes 59 days instead of 40, thus lowering the average.


I have tried below three different calculations to get the right denominator, but all of these are counting 28 days in Feb instead of counting days in Feb till today i.e. 9th Feb :

  • COUNTROWS(CALCULATETABLE(DATESYTD('Date'[Date],"30/06"))) --- Wherein the Date is the date calendar in out model.
  • TOTALYTD(COUNTROWS('Date'),'Date'[Date],"6/30")
  • CALCULATE(INT(MAX('Date'[Date]) - MIN('Date'[Date]) + 1))

How to get the count of dates only till current date in the denomintor.

 

Here the time period selected can be in terms of Financial Year instead of Calenday Year, still the denominator should be counting the days from 01-July-2020 till 09-Feb-2021 if current financial year is selected.

1 ACCEPTED SOLUTION
RachnaV
Helper I
Helper I

Measure that is working with all filters :

Thanks for the help and for responding with the solution. It was working fine if the only filters applied on report were from Date table but any filter on Hospital name or ward name was breaking the measure.  I was able to come up with the measure that worked fine with all the different filters on report.

It is :

NumberOfDays := 

VAR MaxDate = MAX('Date'[Date])
VAR CurrentDate = TODAY()

RETURN
IF ( MaxDate >= CurrentDate,
COUNTROWS(CALCULATETABLE('Date', FILTER('Date','Date'[Date] < CurrentDate))),
COUNTROWS('Date')
)

View solution in original post

2 REPLIES 2
RachnaV
Helper I
Helper I

Measure that is working with all filters :

Thanks for the help and for responding with the solution. It was working fine if the only filters applied on report were from Date table but any filter on Hospital name or ward name was breaking the measure.  I was able to come up with the measure that worked fine with all the different filters on report.

It is :

NumberOfDays := 

VAR MaxDate = MAX('Date'[Date])
VAR CurrentDate = TODAY()

RETURN
IF ( MaxDate >= CurrentDate,
COUNTROWS(CALCULATETABLE('Date', FILTER('Date','Date'[Date] < CurrentDate))),
COUNTROWS('Date')
)

amitchandak
Super User
Super User

@RachnaV , Try a measure like

 

Avg YTD Sales =
divide(CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31")),CALCULATE(countx(filter(values('Date'[Date]), not(isblank(calculate(SUM(Sales[Sales Amount]))))),'Date'[Date])))

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

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.