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
magnus_b
Advocate II
Advocate II

Find previous event in an event log using DAX

Hi,

 

I have data like this:

 

case_idtimestampevent
9928828.10.2020 08:55:32created
7126328.10.2020 09:28:32created
9928828.10.2020 09:29:00assigned
9928828.10.2020 09:39:04solved
7126328.10.2020 10:44:02solved
8710028.10.2020 10:55:01created
7126328.10.2020 11:22:46reopened

 

I want to calculate a new column that contains the previos event for the same case id:

case_idtimestampeventprevious_event
9928828.10.2020 08:55:32created 
7126328.10.2020 09:28:32created 
9928828.10.2020 09:29:00assignedcreated
9928828.10.2020 09:39:04solvedassigned
7126328.10.2020 10:44:02solvedcreated
8710028.10.2020 10:55:01created 
7126328.10.2020 11:22:46reopenedsolved

 

How can I achieve this using DAX?

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@magnus_b - Something like this should work:

 

Column = 
  VAR __PreviousTime = MAXX(FILTER('Table',[case_id] = EARLIER([case_id]) && [timestamp] 
 < EARLIER([timestamp])),[timestamp])
  VAR __PreviousState = MAXX(FILTER('Table',[case_id]=EARLIER([case_id]) && [timestamp]=__PreviousTime),[event])
RETURN
  __PreviousState

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

4 REPLIES 4
magnus_b
Advocate II
Advocate II

@Greg_Deckler I have a more specific definition of what we are after, that might be easier to create a compatible measure to calculate. What we are really after, is the count of case_id that left the "assigned" state today (i.e. the previous_event = "assigned"). We cannot simply count the case_id that entered the "solved" state, because in reality our data is more complex and that won't give us the correct results.

magnus_b
Advocate II
Advocate II

@Greg_Deckler Hi again! I met another challenge, when trying to acheive the same in a source set up with direct query. The MAXX function is not allowed for direct query sources. Do you have a suggestion for how to solve that? Thank you so much for your help!

Greg_Deckler
Super User
Super User

@magnus_b - Something like this should work:

 

Column = 
  VAR __PreviousTime = MAXX(FILTER('Table',[case_id] = EARLIER([case_id]) && [timestamp] 
 < EARLIER([timestamp])),[timestamp])
  VAR __PreviousState = MAXX(FILTER('Table',[case_id]=EARLIER([case_id]) && [timestamp]=__PreviousTime),[event])
RETURN
  __PreviousState

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler That worked beautifully! Thank you!

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.

Top Solution Authors