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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Carrhill
Helper I
Helper I

Create a Measure which Filters on a specific date range

Hi,

I need to create a Filter Measure to show the Item IDs which were opened during a specified date range (30 Jan 2021 - 28 Jan 2022).

 

Here's what I have so far but now I'm stuck...Please help!

 

Opened_In_FY22 = CALCULATE(sum('Table'[Item ID]),FILTER('Table', 'Table'[Opened Date] ????
 

 

Thanks!

1 ACCEPTED SOLUTION
Samarth_18
Community Champion
Community Champion

Hi @Carrhill ,

 

If its static date range then you can try this:-

Opened_In_FY22 =
CALCULATE (
    SUM ( 'Table'[Item ID] ),
    FILTER (
        'Table',
        'Table'[Opened Date] >= DATE ( 2021, 01, 30 )
            && 'Table'[Opened Date] <= DATE ( 2022, 01, 28 )
    )
)

 

or if its coming from date slicer then

 

Opened_In_FY22 =
var min_date = min(date_slicer[date])
var max_date = max(date_slicer[date])
CALCULATE (
    SUM ( 'Table'[Item ID] ),
    FILTER (
        'Table',
        'Table'[Opened Date] >= min_date 
            && 'Table'[Opened Date] <= max_date 
    )
)

 

Thanks,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

View solution in original post

2 REPLIES 2
Samarth_18
Community Champion
Community Champion

Hi @Carrhill ,

 

If its static date range then you can try this:-

Opened_In_FY22 =
CALCULATE (
    SUM ( 'Table'[Item ID] ),
    FILTER (
        'Table',
        'Table'[Opened Date] >= DATE ( 2021, 01, 30 )
            && 'Table'[Opened Date] <= DATE ( 2022, 01, 28 )
    )
)

 

or if its coming from date slicer then

 

Opened_In_FY22 =
var min_date = min(date_slicer[date])
var max_date = max(date_slicer[date])
CALCULATE (
    SUM ( 'Table'[Item ID] ),
    FILTER (
        'Table',
        'Table'[Opened Date] >= min_date 
            && 'Table'[Opened Date] <= max_date 
    )
)

 

Thanks,

Samarth

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Syk
Super User
Super User

Instead of FILTER use the DATESBETWEEN function. If you need specific dates you can just type them with some double quotes!

CALCULATE(SUM('Table'[Item ID], DATESBETWEEN('Table'[Date],MAX('Table'[Opened Date]),TODAY()))

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.