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
Sjrombouts
New Member

Time duration for check in out times

All,

 

I am trying to create the duration (Time difference) per user log in/out.

Table with my data

date_timeactionName
3/27/2023 8:54Checking InAhmed Mohamed
3/28/2023 8:28Checking InAhmed Mohamed
3/27/2023 12:36Checking OutAhmed Mohamed
3/28/2023 12:58Checking OutAhmed Mohamed
3/27/2023 9:49Checking InAndres Edmundo  Espinosa Gutierrez
3/28/2023 8:27Checking InAndres Edmundo Espinosa Gutierrez
3/27/2023 16:15Checking OutAndres Edmundo Espinosa Gutierrez
3/28/2023 7:50Checking InAnthony Baraja
3/28/2023 16:53Checking OutAnthony Baraja
3/27/2023 8:00Checking InCarlos  Cabrera
3/28/2023 7:59Checking InCarlos  Cabrera
3/28/2023 17:07Checking OutCarlos  Cabrera
3/27/2023 8:02Checking InCarlos  Mendoza
3/28/2023 8:03Checking InCarlos  Mendoza
3/27/2023 19:12Checking OutCarlos  Mendoza
3/28/2023 20:12Checking OutCarlos  Mendoza
3/27/2023 17:10Checking OutCarlos Cabrera
3/27/2023 8:00Checking InChristopher  Tamayo Cazarez
3/28/2023 7:59Checking InChristopher  Tamayo Cazarez
3/27/2023 17:10Checking OutChristopher  Tamayo Cazarez
3/28/2023 17:07Checking OutChristopher  Tamayo Cazarez
3/27/2023 10:04Checking InClovis  Mepon Kamgang
3/27/2023 16:00Checking OutClovis  Mepon Kamgang
3/28/2023 11:12Checking InClovis  Mepon Kamgangkamgang
3/28/2023 14:07Checking OutClovis  Mepon Kamgangkamgang
3/27/2023 8:54Checking InDameion Dismuke
3/28/2023 8:28Checking InDameion Dismuke
3/27/2023 17:38Checking OutDameion Dismuke

 

Based on information found on this website

 

Measure = 
var current_user=LASTNONBLANK('Daily Check in_out','Daily Check in_out'[Name])
var current_date=MAX('Daily Check in_out'[date_time])
var current_state=LASTNONBLANK('Daily Check in_out','Daily Check in_out'[action])
var min_date=switch(current_state,"Checking In",current_date,"Checking Out",maxx(FILTER(ALL('Daily Check in_out'),'Daily Check in_out'[Name]=current_user&&'Daily Check in_out'[date_time]<current_date),'Daily Check in_out'[date_time]))
var max_date=switch(current_state,"Checking In",minx(FILTER(ALL('Daily Check in_out'),'Daily Check in_out'[Name]=current_user&&'Daily Check in_out'[date_time]>current_date),'Daily Check in_out'[date_time]),"checking Out",current_date)
return
DATEDIFF(min_date,max_date,HOUR)

 

 But I receive an error:

The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.

 

Anyone with a direction where I go wrong with this?

1 ACCEPTED SOLUTION
Sjrombouts
New Member

Never mind I know what I did wrong.

I was using date_time but i should use my timestamp column

Measure =
var current_user=LASTNONBLANK('Daily Check in_out'[Name],'Daily Check in_out'[Name])
var current_date=MAX('Daily Check in_out'[Timestamp])
var current_state=LASTNONBLANK('Daily Check in_out'[action],'Daily Check in_out'[action])
var min_date=switch(current_state,"Checking In",current_date,"Checking Out",maxx(FILTER(ALL('Daily Check in_out'),'Daily Check in_out'[Name]=current_user&&'Daily Check in_out'[Timestamp]<current_date),'Daily Check in_out'[Timestamp]))
var max_date=switch(current_state,"Checking In",minx(FILTER(ALL('Daily Check in_out'),'Daily Check in_out'[Name]=current_user&&'Daily Check in_out'[Timestamp]>current_date),'Daily Check in_out'[Timestamp]),"checking Out",current_date)
return
DATEDIFF(min_date,max_date,HOUR)

 

View solution in original post

1 REPLY 1
Sjrombouts
New Member

Never mind I know what I did wrong.

I was using date_time but i should use my timestamp column

Measure =
var current_user=LASTNONBLANK('Daily Check in_out'[Name],'Daily Check in_out'[Name])
var current_date=MAX('Daily Check in_out'[Timestamp])
var current_state=LASTNONBLANK('Daily Check in_out'[action],'Daily Check in_out'[action])
var min_date=switch(current_state,"Checking In",current_date,"Checking Out",maxx(FILTER(ALL('Daily Check in_out'),'Daily Check in_out'[Name]=current_user&&'Daily Check in_out'[Timestamp]<current_date),'Daily Check in_out'[Timestamp]))
var max_date=switch(current_state,"Checking In",minx(FILTER(ALL('Daily Check in_out'),'Daily Check in_out'[Name]=current_user&&'Daily Check in_out'[Timestamp]>current_date),'Daily Check in_out'[Timestamp]),"checking Out",current_date)
return
DATEDIFF(min_date,max_date,HOUR)

 

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.