cancel
Showing results for 
Search instead for 
Did you mean: 
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')
)

View solution in original post

amitchandak
Super User IV
Super User IV

@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])))



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Top Solution Authors