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.
Hi,
I have data like this:
case_id | timestamp | event |
99288 | 28.10.2020 08:55:32 | created |
71263 | 28.10.2020 09:28:32 | created |
99288 | 28.10.2020 09:29:00 | assigned |
99288 | 28.10.2020 09:39:04 | solved |
71263 | 28.10.2020 10:44:02 | solved |
87100 | 28.10.2020 10:55:01 | created |
71263 | 28.10.2020 11:22:46 | reopened |
I want to calculate a new column that contains the previos event for the same case id:
case_id | timestamp | event | previous_event |
99288 | 28.10.2020 08:55:32 | created | |
71263 | 28.10.2020 09:28:32 | created | |
99288 | 28.10.2020 09:29:00 | assigned | created |
99288 | 28.10.2020 09:39:04 | solved | assigned |
71263 | 28.10.2020 10:44:02 | solved | created |
87100 | 28.10.2020 10:55:01 | created | |
71263 | 28.10.2020 11:22:46 | reopened | solved |
How can I achieve this using DAX?
Solved! Go to Solution.
@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
@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.
@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!
@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
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
47 | |
26 | |
19 | |
14 | |
10 |
User | Count |
---|---|
58 | |
50 | |
44 | |
19 | |
19 |