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
Anonymous
Not applicable

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: 

DateTimeType
1/1/2020 12:00abc
1/1/2020 12:30abc
1/1/2020 12:31xyz
1/1/2020 13:30xyz
1/1/2020 14:00 abc
2/1/2020 10:20abc
2/1/2020 11:15xyz
2/1/2020 11:16 abc
2/1/2020 13:15efg
2/1/2020 16:00xyz
3/1/2020 13:30abc
3/1/2020 14:00 abc
3/1/2020 15:00 xyz
3/1/2020 15:15xyz

 

This is what I want: 

DateTimeTypeDwell time (min)
1/1/2020 12:00abc120
1/1/2020 12:30abc120
1/1/2020 12:31xyz61
1/1/2020 13:30xyz61
1/1/2020 14:00 abc120
2/1/2020 10:20abc56
2/1/2020 11:15xyz285
2/1/2020 11:16 abc56
2/1/2020 13:15efg1
2/1/2020 16:00xyz285
3/1/2020 13:30abc30
3/1/2020 14:00 abc30
3/1/2020 15:00 xyz15
3/1/2020 15:15xyz15

 

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

1 ACCEPTED SOLUTION
az38
Community Champion
Community 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

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

View solution in original post

10 REPLIES 10
az38
Community Champion
Community 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

LinkedIn


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not 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!

Anonymous
Not 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!

az38
Community Champion
Community Champion

Hi @Anonymous 

for me it works fine with your data sample

Снимок.PNG

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


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

Hi @az38, thanks for your reply. My DateTime is definitely in DateTime format, but I just found out that this line didn't catch the date from DateTime, is there anything that went wrong?

var _selectedDay = DATE(YEAR(SELECTEDVALUE('Table'[DateTime])), MONTH(SELECTEDVALUE('Table'[DateTime])),DAY(SELECTEDVALUE('Table'[DateTime])))

 

az38
Community Champion
Community Champion

@Anonymous
Are you trying to create a measure?
Maybe you should just replace “,” to “;” due to localization question.
One more option - share your pbix file without sensitive data and give me a link to help you 🙂

do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

I was trying to create a column for dwell time. 

The comma is working fine for me, but the semicolon is giving me errors. 

I am sorry I couldn't share the data due to privacy concerns, it looks exactly like the sample data but with seconds (e.g. 1/12/2020 01:12:25).

I've tried to create another column for "_selectedDay", but it returned blank, I thought it supposed to return the date?  

_selectedDay = DATE(YEAR(SELECTEDVALUE('Table'[DateTime])), MONTH(SELECTEDVALUE('Table'[DateTime])),DAY(SELECTEDVALUE('Table'[DateTime])))

 

az38
Community Champion
Community Champion

@Anonymous 

try to create new measure, not column

 

do not hesitate to give a kudo to useful posts and mark solutions as solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn
Anonymous
Not applicable

This is what I got from my data, the left table is the original data and the right table is the _selectedDay measure and dwellTime measure, and I really have no idea why this is not working. Please guide me on this, thanks a bunch! 

 

capture.PNG

az38
Community Champion
Community Champion

Hi @Anonymous 

i do not know, it works fine, maybe you just didnt rename datetime to seentime in my statement?

Снимок.PNG

here is my sample pbix-file with your data example https://ufile.io/wgzpm4jz 

 

do not hesitate to give a kudo to useful posts and mark solutions as solution


do not hesitate to give a kudo to useful posts and mark solutions as solution
LinkedIn

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.