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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
mikebi
Helper III
Helper III

count orders after 60 days between dates

Hello,

I need to count the number of orders by email address and Order Date based on the criteria:

1. Only count the order if the previous Order by email address is more then 60 days old.

 

As an example we don't count the second order by Mike because the order date is within 60 days.

We count the second order by Dave because more then 60 days have elapsed. 

 

mikebi_0-1686231496103.png

 

 

 

4 REPLIES 4
Ahmedx
Super User
Super User

pls try this

Count = 
VAR _t1 = 
         [Email]
VAR _tbl =
    FILTER ( ALL ( 'Table' ), 'Table'[Email] = _t1 )
VAR _minDate =
    MINX ( _tbl, [OrderDate] )
RETURN
    SWITCH (
        TRUE (),
        [OrderDate] = _minDate
            || DATEDIFF ( _minDate, [OrderDate], DAY ) > 60, 1,
        0
    )

Screen Capture #1282.png

Hello,

 

This seems  to work:

 

Count =
VAR _t1 =
        SelectedValue(Rolling[Email])

VAR _t2 = SelectedValue(Rolling[OrderDate])

VAR _tbl =
    FILTER ( ALL ( 'Rolling' ), Rolling[Email] = _t1 && Rolling[OrderDate] < _t2 )

VAR _maxDate =
    maxx ( _tbl, [OrderDate] )
RETURN
    SWITCH (
        TRUE (),
        IsBlank(_maxDate)
            || DATEDIFF ( _maxDate, SelectedValue(Rolling[OrderDate]), DAY ) > 60, 1,
        0
    )
lbendlin
Super User
Super User

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.

https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Hello,

This is the sample data. 

 

mike@test.com1/1/2023Yes
mike@test.com2/1/2023No
Dave@test.com1/1/2023Count
Dave@test.com4/1/2023Yes more then 60 days

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors
Top Kudoed Authors