Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
rajasekar_o
Helper V
Helper V

in out time calculation

hi team , i need to calculate in out time 
in time is max of in time on that date 
out time is if the out time available then max of outtime,if ther is no out time then check next day if there is a out time before 8 am then take it as out time of that date .
i give the data 

IDDATETIMEDATE TIME TYPE
RAM29.1.2023.9:30:0029.1.202309:30:00IN
RAM29.1.2023.9:40:0029.1.202309:40:00IN
KUMAR29.1.2023.9:30:0029.1.202309:30:00IN
RAM29.1.2023.16:30:0029.1.202316:30:00OUT
KUMAR29.1.2023.17:30:0029.1.202317:30:00OUT
RAM30.1.2023.9:30:0030.1.202309:30:00IN
KUMAR30.1.2023.10:30:0030.1.202310:30:00IN
RAM31.1.2023.3:30:0031.1.202303:30:00OUT
RAM31.1.2023.3:30:1931.1.202303:30:19OUT

 

rajasekar_o_0-1706598161266.png

expected output

rajasekar_o_1-1706598186006.png

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @rajasekar_o ,

Please follow these steps:

1.Creating intime measure.

 

intime =

VAR time = MAXX(FILTER(ALL('Table'),'Table'[ID] = MAX('Table'[ID]) && 'Table'[DATE ] = MAX('Table'[DATE ]) && 'Table'[TYPE] = "IN"),'Table'[TIME ])

RETURN

FORMAT(time,"hh:mm:ss")

 

2.Creating outtime measure.

 

outtime =

var cur_name=SELECTEDVALUE('Table'[ID])

var cur_dt=SELECTEDVALUE('Table'[DATE ])

var cur_date=DATE(YEAR(cur_dt),MONTH(cur_dt),DAY(cur_dt))

var next_date=cur_date+1

var tmp=FILTER(ALL('Table'),DATE(YEAR([DATE ]),MONTH([DATE ]),DAY([DATE ]))=cur_date&&[TYPE]="OUT"&&'Table'[ID] = cur_name)

var max_date=MAXX(tmp,[DATE ])

VAR time = MAXX(tmp,[TIME ])

var max_time=TIME(HOUR(time),MINUTE(time),SECOND(time))

var tmp2=FILTER(ALL('Table'),[ID]=cur_name&&DATE(YEAR([DATE ]),MONTH([DATE ]),DAY([DATE ]))=next_date&&[Type]="OUT")

var tmp3=FILTER(tmp2,[TIME ]<TIMEVALUE("8.00.00"))

var max_time1=MAXX(tmp3,[TIME ])

RETURN

IF(ISBLANK(COUNTROWS(tmp)),

FORMAT(max_time1,"hh:mm:ss"),

FORMAT(max_time,"hh:mm:ss")

)

 

3.Create another measure for filtering dates with only OUT.

 

Measure =

var _select=SELECTCOLUMNS(FILTER(ALL('Table'),'Table'[ID]=MAX('Table'[ID])&&'Table'[DATE ]=MAX('Table'[DATE ])),"Type1",[TYPE])

return

IF(

    "IN" in _select,1,0)

 

The settings inside filters are shown below.

vkaiyuemsft_0-1706669692819.png

4.The result obtained is shown below.

vkaiyuemsft_1-1706669717483.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @rajasekar_o ,

Please follow these steps:

1.Creating intime measure.

 

intime =

VAR time = MAXX(FILTER(ALL('Table'),'Table'[ID] = MAX('Table'[ID]) && 'Table'[DATE ] = MAX('Table'[DATE ]) && 'Table'[TYPE] = "IN"),'Table'[TIME ])

RETURN

FORMAT(time,"hh:mm:ss")

 

2.Creating outtime measure.

 

outtime =

var cur_name=SELECTEDVALUE('Table'[ID])

var cur_dt=SELECTEDVALUE('Table'[DATE ])

var cur_date=DATE(YEAR(cur_dt),MONTH(cur_dt),DAY(cur_dt))

var next_date=cur_date+1

var tmp=FILTER(ALL('Table'),DATE(YEAR([DATE ]),MONTH([DATE ]),DAY([DATE ]))=cur_date&&[TYPE]="OUT"&&'Table'[ID] = cur_name)

var max_date=MAXX(tmp,[DATE ])

VAR time = MAXX(tmp,[TIME ])

var max_time=TIME(HOUR(time),MINUTE(time),SECOND(time))

var tmp2=FILTER(ALL('Table'),[ID]=cur_name&&DATE(YEAR([DATE ]),MONTH([DATE ]),DAY([DATE ]))=next_date&&[Type]="OUT")

var tmp3=FILTER(tmp2,[TIME ]<TIMEVALUE("8.00.00"))

var max_time1=MAXX(tmp3,[TIME ])

RETURN

IF(ISBLANK(COUNTROWS(tmp)),

FORMAT(max_time1,"hh:mm:ss"),

FORMAT(max_time,"hh:mm:ss")

)

 

3.Create another measure for filtering dates with only OUT.

 

Measure =

var _select=SELECTCOLUMNS(FILTER(ALL('Table'),'Table'[ID]=MAX('Table'[ID])&&'Table'[DATE ]=MAX('Table'[DATE ])),"Type1",[TYPE])

return

IF(

    "IN" in _select,1,0)

 

The settings inside filters are shown below.

vkaiyuemsft_0-1706669692819.png

4.The result obtained is shown below.

vkaiyuemsft_1-1706669717483.png

If your Current Period does not refer to this, please clarify in a follow-up reply.

 

Best Regards,

Clara Gong

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@rajasekar_o ,

Measure like

intime=

minx(filter(Table, Table[Type] = "IN"), Table[intime])

 

outtime =

maxx(filter(Table, Table[Type] = "OUT"), Table[intime])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors