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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors