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