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
Anonymous
Not applicable

Counting number of Dates in a Filter

I am working on my dashboard and I came across a problem:

I need to create a measure to calculate how many days are included in my filter (ex. Jan1 - March 31 = 89 days)

 

My filter is in the upper right hand corner to get these dates from.... just not sure how to go about this!

nattiej101_0-1618938415832.png

 

1 ACCEPTED SOLUTION
v-angzheng-msft
Community Support
Community Support

 Hi, @Anonymous 

Refer to the method provided by @amitchandak 

Days:
Just use the method provided by @amitchandak 

_Count days =
VAR _max =
    MAXX ( ALLSELECTED ( 'Date' ), 'Date'[date] )
VAR _min =
    MINX ( ALLSELECTED ( 'Date' ), 'Date'[date] )
RETURN
    DATEDIFF ( _min, _max, DAY ) + 1

For counting weeks, it's not clear whether you want interval weeks based on the calendar or on the number of days in the interval.

Weeks: On days

_Count days(Week) =
VAR _max =
    MAXX ( ALLSELECTED ( 'Date' ), 'Date'[date] )
VAR _min =
    MINX ( ALLSELECTED ( 'Date' ), 'Date'[date] )
RETURN
    ROUNDUP ( DIVIDE ( DATEDIFF ( _min, _max, DAY ) + 1, 7 ), 0 )

Weeks: On Calendar

_Count weeks =
VAR _max =
    MAXX ( ALLSELECTED ( 'Date' ), 'Date'[date] )
VAR _min =
    MINX ( ALLSELECTED ( 'Date' ), 'Date'[date] )
RETURN
    DATEDIFF ( _min, _max, WEEK ) + 1

 

Is this the result you want? Hope this is useful to you

Please feel free to let me know If you have further questions

 

 

Best Regards,
Community Support Team _ Zeon Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-angzheng-msft
Community Support
Community Support

 Hi, @Anonymous 

Refer to the method provided by @amitchandak 

Days:
Just use the method provided by @amitchandak 

_Count days =
VAR _max =
    MAXX ( ALLSELECTED ( 'Date' ), 'Date'[date] )
VAR _min =
    MINX ( ALLSELECTED ( 'Date' ), 'Date'[date] )
RETURN
    DATEDIFF ( _min, _max, DAY ) + 1

For counting weeks, it's not clear whether you want interval weeks based on the calendar or on the number of days in the interval.

Weeks: On days

_Count days(Week) =
VAR _max =
    MAXX ( ALLSELECTED ( 'Date' ), 'Date'[date] )
VAR _min =
    MINX ( ALLSELECTED ( 'Date' ), 'Date'[date] )
RETURN
    ROUNDUP ( DIVIDE ( DATEDIFF ( _min, _max, DAY ) + 1, 7 ), 0 )

Weeks: On Calendar

_Count weeks =
VAR _max =
    MAXX ( ALLSELECTED ( 'Date' ), 'Date'[date] )
VAR _min =
    MINX ( ALLSELECTED ( 'Date' ), 'Date'[date] )
RETURN
    DATEDIFF ( _min, _max, WEEK ) + 1

 

Is this the result you want? Hope this is useful to you

Please feel free to let me know If you have further questions

 

 

Best Regards,
Community Support Team _ Zeon Zheng
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , Try a measure like

 

New measure =
var _max = maxx(allselected('Date', 'Date'[date])
var _min= minx(allselected('Date', 'Date'[date])
return
datediff(_min,_max, day) // add +1 if needed ie::  datediff(_min,_max, day) +1

Anonymous
Not applicable

That works!  How would I do it to count weeks? (weeks instead of days?)

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.