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
Syndicate_Admin
Administrator
Administrator

Calcular columna con tiempo desde la entrada

Tengo una tabla de registros, con cada fila teniendo una fecha única.
La tabla contiene información sobre las personas que entran y salen de un estado, así como su estado.
¿Cómo calculo una columna que registre la diferencia de tiempo entre la entrada y la salida (días) en el momento de la salida?

mesa:

FechaTimeidentificaciónestadoentradasalida
25/10/2020 14:251001A
29/10/2020 14:251001B10
1/12/2020 15:301002 10
5/02/2021 12:001001B01
15/04/2021 21:451002

0

1
20/04/2021 21:451003A00


Mi resultado esperado es:

FechaTimeidentificaciónTiempo desde la entrada
5/02/2021 12:00100199
15/04/2021 21:451003135


Quiero poder decir - En abril el tiempo promedio desde la entrada fue de 135 días.

Tengo una medida que calcula el tiempo desde la entrada:

Time Since Entry = 
AVERAGEX(
    VALUES('Table'[ID]), 
        CALCULATE(
            DATEDIFF(
                MINX(FILTER('Table', 'Table'[Entry] =1), [DateTime]),
                MAXX(FILTER('Table', 'Table'[Exit] =1), [DateTime]),
                DAY)
        )
    )

Sin embargo, el problema es que cuando filtro esta medida en mi informe por mes excluye el datetime de entrada cuando la entrada no está en abril.


Por lo tanto, quiero calcular una columna y probé el siguiente DAX:

Time Since Entry = 
IF(
    'Table'[Exit] = 1,
    AVERAGEX(
        VALUES('Table'[ID]), 
            CALCULATE(
                DATEDIFF(
                    MINX(FILTER('Table', 'Table'[Entry] =1), [DateTime]),
                    MAXX(FILTER('Table', 'Table'[Exit] =1), [DateTime]),
                    DAY)
            )
    ),
    9999997
)


Sin embargo, esto me da:

FechaTimeidentificaciónStatus_AentradasalidaTiempo desde la entrada
25/10/2020 14:251001A 99999997
29/10/2020 14:251001 1099999997
1/12/2020 15:301002 1099999997
5/02/2021 12:001001 01
15/04/2021 21:451002 01


Primer post:
https://community.powerbi.com/t5/Desktop/DATEDIFF-between-DateTime-Values-by-ID/m-p/1838306#M711595

Problemas similares:
https://community.powerbi.com/t5/Desktop/Calculating-time-difference/m-p/1528385#M628335
https://community.powerbi.com/t5/DAX-Commands-and-Tips/DATEDIFF-with-filter/m-p/769728
https://community.powerbi.com/t5/Desktop/using-datediff-with-filters/m-p/528938

1 ACCEPTED SOLUTION
Syndicate_Admin
Administrator
Administrator

@moosepng , Crear una columna como esta y tomar un promedio de que

if([Exit] =1, datediff(maxx(filter('Table', [ID] =earlier([ID]) && [Entry] =1 && [DateTime] <= anterior([DateTime])),[DateTime]),[DateTime], day), blank())

View solution in original post

2 REPLIES 2
Syndicate_Admin
Administrator
Administrator

¡Gracias Amigo!

Syndicate_Admin
Administrator
Administrator

@moosepng , Crear una columna como esta y tomar un promedio de que

if([Exit] =1, datediff(maxx(filter('Table', [ID] =earlier([ID]) && [Entry] =1 && [DateTime] <= anterior([DateTime])),[DateTime]),[DateTime], day), blank())

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.