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

Boolean if order placed within 24 hr rolling period from last order

Hi guys, 

 

I have a rather complicated one. I would like to create a calculated column that has TRUE/FALSE if a user's order was placed within a rolling 24 HR time period from the last order, and the status is not "Canceled" : 

 

User IdOrder Created AtStatus24HR rolling
101033/2/21 12:00CANCELEDFalse
101376/30/21 8:00COMPLETEDTrue
101376/29/21 22:00TransferringTrue
101614/3/21 22:00CANCELEDFalse
101614/3/21 18:00PENDINGTrue
101614/3/21 12:00COMPLETEDTrue

 

Would anyone know how to do this? 

 

Thank you, 

 

Denisse

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

Hi @ruesaint_denis ,

According to your description, I modify your sample data like this:

vkalyjmsft_0-1643267465694.png

In my understanding, for user ID 10161, the last created order is "4/4/21 16:00:00", then the time "4/3/21 12:00:00" is over 24 hours for the last created order "4/4/21 16:00:00", so it's  value should be false, others in my sample should be true, right? If it is like this, I modify @VahidDM 's formula like this:

24HR rolling =
VAR _LAST =
    CALCULATE (
        MAX ( 'Table'[Order Created At] ),
        ALLEXCEPT ( 'Table', 'Table'[User Id] )
    )
VAR _NOW = 'Table'[Order Created At]
VAR _HR =
    DATEDIFF ( _NOW, _LAST, HOUR )
RETURN
    IF ( _HR < 24 && 'Table'[Status] <> "CANCELED", TRUE (), FALSE () )

If you still have other problems, please feel free to let me know.

I attach my sample below for reference.

Best Regards,
Community Support Team _ kalyj

 

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

2 REPLIES 2
v-yanjiang-msft
Community Support
Community Support

Hi @ruesaint_denis ,

According to your description, I modify your sample data like this:

vkalyjmsft_0-1643267465694.png

In my understanding, for user ID 10161, the last created order is "4/4/21 16:00:00", then the time "4/3/21 12:00:00" is over 24 hours for the last created order "4/4/21 16:00:00", so it's  value should be false, others in my sample should be true, right? If it is like this, I modify @VahidDM 's formula like this:

24HR rolling =
VAR _LAST =
    CALCULATE (
        MAX ( 'Table'[Order Created At] ),
        ALLEXCEPT ( 'Table', 'Table'[User Id] )
    )
VAR _NOW = 'Table'[Order Created At]
VAR _HR =
    DATEDIFF ( _NOW, _LAST, HOUR )
RETURN
    IF ( _HR < 24 && 'Table'[Status] <> "CANCELED", TRUE (), FALSE () )

If you still have other problems, please feel free to let me know.

I attach my sample below for reference.

Best Regards,
Community Support Team _ kalyj

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

VahidDM
Super User
Super User

Hi @ruesaint_denis 

 

Try this to add a new column with DAX:

24HR rolling =
VAR _MAXT =
    CALCULATE (
        MAX ( 'Table'[Order Created At] ),
        ALLEXCEPT ( 'Table', 'Table'[User Id] )
    )
VAR _MINT =
    CALCULATE (
        MIN ( 'Table'[Order Created At] ),
        ALLEXCEPT ( 'Table', 'Table'[User Id] )
    )
VAR _HR =
    DATEDIFF ( _MINT, _MAXT, HOUR )
RETURN
    IF ( _HR < 24 && 'Table'[Status] <> "CANCELED", TRUE (), FALSE () )

 

output:

VahidDM_0-1643065543746.png

 

 

 

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
LinkedIn: 
www.linkedin.com/in/vahid-dm/

 

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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