Forum Discussion
Finding dwell time
Hi, I am struggling to find dwell time with dax, would really appreciate if anyone could guide me on this.
Sample dataset:
| DateTime | Type |
| 1/1/2020 12:00 | abc |
| 1/1/2020 12:30 | abc |
| 1/1/2020 12:31 | xyz |
| 1/1/2020 13:30 | xyz |
| 1/1/2020 14:00 | abc |
| 2/1/2020 10:20 | abc |
| 2/1/2020 11:15 | xyz |
| 2/1/2020 11:16 | abc |
| 2/1/2020 13:15 | efg |
| 2/1/2020 16:00 | xyz |
| 3/1/2020 13:30 | abc |
| 3/1/2020 14:00 | abc |
| 3/1/2020 15:00 | xyz |
| 3/1/2020 15:15 | xyz |
This is what I want:
| DateTime | Type | Dwell time (min) |
| 1/1/2020 12:00 | abc | 120 |
| 1/1/2020 12:30 | abc | 120 |
| 1/1/2020 12:31 | xyz | 61 |
| 1/1/2020 13:30 | xyz | 61 |
| 1/1/2020 14:00 | abc | 120 |
| 2/1/2020 10:20 | abc | 56 |
| 2/1/2020 11:15 | xyz | 285 |
| 2/1/2020 11:16 | abc | 56 |
| 2/1/2020 13:15 | efg | 1 |
| 2/1/2020 16:00 | xyz | 285 |
| 3/1/2020 13:30 | abc | 30 |
| 3/1/2020 14:00 | abc | 30 |
| 3/1/2020 15:00 | xyz | 15 |
| 3/1/2020 15:15 | xyz | 15 |
I am trying to find the dwell time for each type on daily basis, is there any possible way to do it? Have you ever seen anything like this? Would really appreciate some help! Thanks xoxo
Hi Anonymous
try to create a measure
dwellTime = var _selectedDay = DATE(YEAR(SELECTEDVALUE('Table'[DateTime])), MONTH(SELECTEDVALUE('Table'[DateTime])),DAY(SELECTEDVALUE('Table'[DateTime]))) var _start = CALCULATE(MIN('Table'[DateTime]),FILTER(ALL('Table'),'Table'[Type]=SELECTEDVALUE('Table'[Type]) && DATE(YEAR('Table'[DateTime]),MONTH('Table'[DateTime]),DAY('Table'[DateTime]))=_selectedDay)) var _end = CALCULATE(MAX('Table'[DateTime]),FILTER(ALL('Table'),'Table'[Type]=SELECTEDVALUE('Table'[Type]) && DATE(YEAR('Table'[DateTime]),MONTH('Table'[DateTime]),DAY('Table'[DateTime]))=_selectedDay)) return IF(_end>_start,datediff(_start,_end,MINUTE),1)do not hesitate to give a kudo to useful posts and mark solutions as solution
10 Replies
- az38Community Champion
Hi Anonymous
try to create a measure
dwellTime = var _selectedDay = DATE(YEAR(SELECTEDVALUE('Table'[DateTime])), MONTH(SELECTEDVALUE('Table'[DateTime])),DAY(SELECTEDVALUE('Table'[DateTime]))) var _start = CALCULATE(MIN('Table'[DateTime]),FILTER(ALL('Table'),'Table'[Type]=SELECTEDVALUE('Table'[Type]) && DATE(YEAR('Table'[DateTime]),MONTH('Table'[DateTime]),DAY('Table'[DateTime]))=_selectedDay)) var _end = CALCULATE(MAX('Table'[DateTime]),FILTER(ALL('Table'),'Table'[Type]=SELECTEDVALUE('Table'[Type]) && DATE(YEAR('Table'[DateTime]),MONTH('Table'[DateTime]),DAY('Table'[DateTime]))=_selectedDay)) return IF(_end>_start,datediff(_start,_end,MINUTE),1)do not hesitate to give a kudo to useful posts and mark solutions as solution
- AnonymousNot applicable
Hi az38 , thanks for your reply but I am getting 1 min for each row instead of getting the dwell time. 😞 Is there any other possible way? Thanks for your help!
- az38Community Champion
Hi Anonymous
for me it works fine with your data sample
maybe you have something else in your data model? or your datetime field has no datetime data type?
do not hesitate to give a kudo to useful posts and mark solutions as solution
- AnonymousNot applicable
Thanks az38 ! I guess this will definitely works on a smaller dataset. My dataset is a bit too huge and I have split it up to three parts and it is working fine now!