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
saranp780
Helper III
Helper III

¿Cómo contar los tiempos en la tabla???

Tengo la tabla que contiene la información sobre Inicio de sesión y cierre de sesión que mi cliente inicia sesión en nuestro sistema.

FechaHoraUsuarioTipo
1.06.20200:05:38ASesión
1.06.20200:06:40BSesión
1.06.20206:20:21CSesión
1.06.20208:21:10ACerrar sesión
1.06.20208:22:10DSesión
1.06.20209:25:00BCerrar sesión
1.06.202010:40:41ASesión
1.06.202010:41:11CCerrar sesión
1.06.202011:01:50DCerrar sesión
1.06.202012:21:02ACerrar sesión

Así que ahora me gustaría rastrear su tiempo en el sistema que cuánto tiempo pasaron? Necesito calcular el tiempo como el usuario A Inicio de sesión 2 veces y tiempo pasado en el sistema XXX horas XXX minutos.

Creo que puedo usar la columna de tiempo para calcular entre type(logon y logout) para el mismo usuario, pero no sé qué DAX puedo usar?

Si alguien me habla del Dax, gracias a todos tus expertos.

4 REPLIES 4
v-shex-msft
Community Support
Community Support

Hola @saranp780,

Puede utilizar la siguiente fórmula DAX para crear una nueva tabla calculada para resumen de tiempos de registro y duración total:

Summary = 
VAR temp =
    ADDCOLUMNS (
        'Table',
        "Duration", IF (
            [Type] = "Logon",
            DATEDIFF (
                [Time],
                CALCULATE (
                    MIN ( 'Table'[Time] ),
                    FILTER (
                        'Table',
                        [Date] = AVERAGE ( 'Table'[Date] )
                            && [User] = EARLIER ( 'Table'[User] )
                            && [Type] <> EARLIER ( 'Table'[Type] )
                            && [Time] > EARLIER ( 'Table'[Time] )
                    )
                ),
                SECOND
            )
        )
    )
RETURN
    ADDCOLUMNS (
        SUMMARIZE (
            temp,
            [Date],
            [User],
            "Count", COUNTX (
                FILTER (
                    temp,
                    [Date] = EARLIER ( 'Table'[Date] )
                        && [User] = EARLIER ( 'Table'[User] )
                ),
                [Duration]
            ),
            "TotalSeconds", SUMX (
                FILTER (
                    temp,
                    [Date] = EARLIER ( 'Table'[Date] )
                        && [User] = EARLIER ( 'Table'[User] )
                ),
                [Duration]
            )
        ),
        "Duration",
        VAR _hour =
            ROUNDUP ( [TotalSeconds] / 3600, 0 )
        VAR _minute =
            ROUNDUP ( MOD ( [TotalSeconds], 3600 ) / 60, 0 )
        RETURN
            _hour & ":" & _minute & ":"
                & ROUNDUP ( MOD ( MOD ( [TotalSeconds], 3600 ), 60 ), 0 )
    )

saludos

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

@v-shex-msft Ya lo intenté, pero se redondeó como el usuario A como calculé en Excel:

9:55:53 pero en esta fórmula 10:56:55

Hola @saranp780,

¿Puede compartir un archivo de muestra con algunos datos ficticios para probar? (no adjunte datos confidenciales)
saludos

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
amitchandak
Super User
Super User

@saranp780 , pruebe una nueva columna

Columna: if( [Type],3) á "Logoff" ,datediff( Maxx(FILTER(Sheet1,[User]-EARLIER(Sheet1[User]) && [Date time] <EARLIER([date time]) && ([Type]) ? "start" ),[Timestamp]),[Timestamp],MINUTE),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.