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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Anonymous
Not applicable

Customer First Purchase Date Time after Failed Transactions - within next 24 hours

Good Day! 

I'm looking to fix one of the issues, where I have to find the Customer First Purchase Date Time after Failed Transactions - within next 24 hours

Also, Please find the Table : SampleData as below :SampleData.png

For example : If CustomerID - 60001 has failed transaction on DateTime (1/1/2022 10:30AM) then had he purchased within 24 hours after failed tranaction as per orderstatus Column value- "Failed".

And, CustomerID-60001 has next purchase with in 24 hours.

Considerational Note : CustomerID 60008 has multiple failed tranaction.

Looking forward to have your best response. 

Thanks in Advance 😊

2 ACCEPTED SOLUTIONS
lukiz84
Memorable Member
Memorable Member

Hi, the easiest way is to add a calculated column, something like this:

 

 

 

FirstPurchasedAfterFailed := 
   VAR LastFailed = 
       CALCULATE(
           MAX(SampleData[DateTime]),
           FILTER(
              SampleData,
              SampleData[CustomerId] = EARLIER(SampleData[CustomerId]) &&
              SampleData[DateTime] < EARLIER(SampleData[DateTime]) && 
              SampleData[orderstatus] = "Failed"
           )
        )
    RETURN
       IF(
          NOT(ISBLANK(LastFailed)) &&
          SampleData[orderstatus] = "Authorized" &&
          LastFailed >= SampleData[DateTime] - 1,
          SampleData[DateTime]
       ) 
              

 

 

 

In your new Column you then always have the latest succesful DateTime after a failed transaction.

View solution in original post

Anonymous
Not applicable

Hey! Lukiz84,

Thanks for your wonderful Script, I really appreciate your response.

Thanks a lot!

View solution in original post

3 REPLIES 3
lukiz84
Memorable Member
Memorable Member

You are welcome, have a nice weekend 🙂

lukiz84
Memorable Member
Memorable Member

Hi, the easiest way is to add a calculated column, something like this:

 

 

 

FirstPurchasedAfterFailed := 
   VAR LastFailed = 
       CALCULATE(
           MAX(SampleData[DateTime]),
           FILTER(
              SampleData,
              SampleData[CustomerId] = EARLIER(SampleData[CustomerId]) &&
              SampleData[DateTime] < EARLIER(SampleData[DateTime]) && 
              SampleData[orderstatus] = "Failed"
           )
        )
    RETURN
       IF(
          NOT(ISBLANK(LastFailed)) &&
          SampleData[orderstatus] = "Authorized" &&
          LastFailed >= SampleData[DateTime] - 1,
          SampleData[DateTime]
       ) 
              

 

 

 

In your new Column you then always have the latest succesful DateTime after a failed transaction.

Anonymous
Not applicable

Hey! Lukiz84,

Thanks for your wonderful Script, I really appreciate your response.

Thanks a lot!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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