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

2 REPLIES 2
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')
)

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

Proud to be a Super User!

Announcements

#### 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.