- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Time difference between date time values in same column based on a value in a different column
Hello,
I am trying to aggregate the time a user has spent in the Receipt function scanning items in the warehouse. How would I get the output in the following table (elapsed seconds):
Assignment 1 | User | Date Time Start | Function | Elapsed Seconds |
1 | JF | 9/30/19 8:16 AM | RECEIPT | 0 |
1 | JF | 9/30/19 8:17 AM | RECEIPT | 60 |
2 | MK | 10/1/19 4:04 PM | RECEIPT | 0 |
2 | MK | 10/1/19 4:10 PM | RECEIPT | 0 |
2 | MK | 10/1/19 4:11 PM | RECEIPT | 420 |
Essentially, I need to aggregate the elapsed seconds by User for the Receipt function. I know I need to use the DATEDIFF between the minimal date/time and max date time for the user that is completing the receipt function, but I am not sure how to have 0 for all values except for the last one (the aggregated value). I guess I could have the number of seconds between each date since power bi will aggregate it anyway. So, to have:
Assignment 1 | User | Date Time Start | Function | Elapsed Seconds |
1 | JF | 9/30/19 8:16 AM | RECEIPT | 0 |
1 | JF | 9/30/19 8:17 AM | RECEIPT | 60 |
2 | MK | 10/1/19 4:04 PM | RECEIPT | 0 |
2 | MK | 10/1/19 4:10 PM | RECEIPT | 360 |
2 | MK | 10/1/19 4:11 PM | RECEIPT | 60 |
The receipt function is not the only function in the dataset, so I would need to filter to that function and aggregate the time by user.
I appreciate the help!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Anonymous ,
Here is the pbix PBIX
I put both columns in so that you have your choice, the second column only shows in the last row of the user. The difference between the measure and the column at the high level, is that with a measure, the engine does not have row context, whereas in the table it does. (It knows which row it is operating on.) Therefore it was just a matter of dropping MAX().
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Anonymous
What is the difference between the two tables?
Nathaniel
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Anonymous ,
If I understand correctly this is what you are looking as an output?
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel
lapse Secs Calc =
VAR _curTime =
MAX ( TimeElapse[Date Time Start] )
VAR _pasttime =
CALCULATE (
MAX ( TimeElapse[Date Time Start] ),
TimeElapse[Date Time Start] < _curTime,
ALLEXCEPT ( TimeElapse, TimeElapse[User], TimeElapse[Function] )
)
VAR _dif =
DATEDIFF ( _pasttime, _curTime, SECOND )
RETURN
_dif
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Nathaniel_C ,
I just imported my example data into a new file and ran your function on it but my results do not match to what you had.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Anonymous ,
Try it as a measure, not a calculated column. Looking at your first picture that is what i built it for. Put the first 5 columns on a table, then add the measure.
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi! Sorry for not specifying that i needed it as a calculated column, because I am doing some other calculations based on the elapsed time. When I return the past time, it is incorrectly returning the time per user. For example, for JF, it should return
9/30/2019 8:16:00 AM and for the MK it should return 10/1/2019 4:11:00 PM. I feel like if I could get this working, the rest of the function would be correct.
I appreciate the help!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Anonymous ,
Here is the pbix PBIX
I put both columns in so that you have your choice, the second column only shows in the last row of the user. The difference between the measure and the column at the high level, is that with a measure, the engine does not have row context, whereas in the table it does. (It knows which row it is operating on.) Therefore it was just a matter of dropping MAX().
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nathaniel,
I have a similar problem. I have a restaurant reservations table. Basically there are just two columns that should go into calculation. PersonName and ReservationDate. I need to calculate the time difference between reservations of the same cusstomer. There may be customers who only reserved once so we don't count them. Only repeating customers count. They may have from two records to many. How can I do that in DAX?
Thansk,
Stan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks so much for your help! This worked!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Anonymous ,
You are welcome!
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Anonymous
Or with zeros.
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel
Elapse Secs Calc =
VAR _curTime =
MAX ( TimeElapse[Date Time Start] )
VAR _pasttime =
CALCULATE (
MAX ( TimeElapse[Date Time Start] ),
TimeElapse[Date Time Start] < _curTime,
ALLEXCEPT ( TimeElapse, TimeElapse[User], TimeElapse[Function] )
)
VAR _dif =
IF(ISBLANK(_pasttime), 0 ,DATEDIFF ( _pasttime, _curTime, SECOND ))
RETURN
_dif
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @Anonymous ,
Here is the solution with only the final value showing for each User and Function.
Only latest value =
VAR _calc = [Cummulative]
VAR _maxDate =
CALCULATE (
MAX ( TimeElapse[Date Time Start] ),
ALLEXCEPT ( TimeElapse, TimeElapse[User], TimeElapse[Function] )
)
RETURN
IF ( MAX ( TimeElapse[Date Time Start] ) = _maxDate, [Cummulative], 0 )
Let me know if you have any questions.
If this solves your issues, please mark it as the solution, so that others can find it easily. Kudos are nice too.
Nathaniel
Did I answer your question? Mark my post as a solution!
Proud to be a Super User!

Helpful resources
Join us at the Microsoft Fabric Community Conference
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Power BI Monthly Update - February 2025
Check out the February 2025 Power BI update to learn about new features.

Subject | Author | Posted | |
---|---|---|---|
04-13-2024 01:19 PM | |||
01-25-2024 06:49 AM | |||
08-20-2024 06:48 PM | |||
07-18-2024 12:30 PM | |||
01-27-2024 02:20 AM |
User | Count |
---|---|
24 | |
13 | |
11 | |
10 | |
9 |
User | Count |
---|---|
18 | |
14 | |
13 | |
12 | |
10 |