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

Data Days is here! Join us now for 60+ days of learning, challenges, and connection. Learn more

Reply
Syndicate_Admin
Administrator
Administrator

Count Entry and exit times

I have a table with the fields: Name Date Type Time Index and Times

Tabla.jpg

The index column has this formula: =CONTAR.SI($A$2:A2,A2)
The times column has this formula: =IF(A3=A2,D3-D2,"")

Those 2 columns are additional to my table

What I want is to load my original table in power pivot and from there add the 2 columns and with dax formulas

Take out the index and get the difference between times.

To later be able to verify how long a user was inside and how long he was outside.

I need to know for each day, how long the user was inside and how long outside, for that I need the time difference.

In excel it is easy to achieve since the formula is manipulated, but I have not been able to do it in dax.

Could someone help me please?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @MaritoDominguez ,

 

You could create two calculated columns as follows.

Index = COUNTROWS(FILTER('Table',[Hora]<=EARLIER('Table'[Hora])&&[Nombre]=EARLIER('Table'[Nombre])))

vstephenmsft_0-1681377091771.png

Diff = var _pre=CALCULATE(MAX('Table'[Hora]),FILTER('Table',[Index]<EARLIER('Table'[Index])&&[Nombre]=EARLIER('Table'[Nombre])))
return IF(ISBLANK(_pre),BLANK(),[Hora]-_pre)

vstephenmsft_1-1681377100371.png

 

You can download the attachment for more details.

 

                                                                                                                                                         

Best Regards,

Stephen Tao

 

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

1 REPLY 1
Anonymous
Not applicable

Hi @MaritoDominguez ,

 

You could create two calculated columns as follows.

Index = COUNTROWS(FILTER('Table',[Hora]<=EARLIER('Table'[Hora])&&[Nombre]=EARLIER('Table'[Nombre])))

vstephenmsft_0-1681377091771.png

Diff = var _pre=CALCULATE(MAX('Table'[Hora]),FILTER('Table',[Index]<EARLIER('Table'[Index])&&[Nombre]=EARLIER('Table'[Nombre])))
return IF(ISBLANK(_pre),BLANK(),[Hora]-_pre)

vstephenmsft_1-1681377100371.png

 

You can download the attachment for more details.

 

                                                                                                                                                         

Best Regards,

Stephen Tao

 

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

Helpful resources

Announcements
Fabric Data Days is here Carousel

Fabric Data Days 2026

Don't miss out on Data Days, June 15 through August 7. Learn Fabric, Power BI, SQL, AI and more.

May Power BI Update Carousel

Power BI Monthly Update - May 2026

Check out the May 2026 Power BI update to learn about new features.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.