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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
MYDATASTORY
Resolver I
Resolver I

DAX Cálculo de tiempo entre dos marcas de tiempo

Hola

Por favor, consejo con fórmulas Dax reales para calcular la diferencia de tiempo.

Si usted es capaz de proporcionar una muestra de DAX basado en los datos de la presa a continuación será genial.

Los datos se presentarán en forma tabular y también en visualización donde la Duración Total (HH: MM) se agrupará por ID y Mes. Muy apreciado de antemano.

Id Hora de inicioHora de finalizaciónResultado esperado en HH: MM
A01:30:0002:00:3000:30:00 HH: MM
B11:00:0003:30:0004:30:00 HH:MM

Respuesta esperada A sobre la mesa

Tiempo total: para A-00:30:00HH:MM

Tiempo total: Para B-04:30:00HH:MM
Respuesta esperada B sobre la mesa

Tiempo total para todos los ID (Tiempo total: para A-00:30:00HH:MM)+(Tiempo total: Para B-04:30:00HH:MM)-05:00HH:MM

4 REPLIES 4
Caroline_1900
Frequent Visitor

Así que eso funciona, pero entonces el tiempo no se sumará en una tabla o matriz. ¿Cómo arreglar esto? Por favor, y gracias.Screenshot 2020-11-30 061321.pngScreenshot 2020-11-30 061627.png

@Caroline_1900,

Prueba esta medida. Se basa en una medida en el siguiente enlace.

https://community.powerbi.com/t5/Community-Blog/Aggregating-Duration-Time/ba-p/22486

Time Diff = 
// Given a number of seconds, returns a format of "hh:mm"
VAR vDuration =
    SUMX ( TimeTracker, DATEDIFF ( TimeTracker[Start_Time], TimeTracker[End_Time], SECOND ) )
// There are 3,600 seconds in an hour
VAR vHours =
    INT ( vDuration / 3600 )
// There are 60 seconds in a minute
VAR vMinutes =
    INT ( MOD ( vDuration - ( vHours * 3600 ), 3600 ) / 60 )
// These intermediate variables ensure that we have leading zeros concatenated onto single digits
// Hours with leading zeros
VAR vHoursFormatted =
    IF ( LEN ( vHours ) = 1, "0" & vHours, "" & vHours )
// Minutes with leading zeros
VAR vMinutesFormatted =
    IF ( LEN ( vMinutes ) = 1, "0" & vMinutes, "" & vMinutes )
// Now return hours and minutes with leading zeros in the proper format "hh:mm"
VAR vResult =
    vHoursFormatted & ":" & vMinutesFormatted
RETURN
    IF ( vResult = ":", BLANK(), vResult )

DataInsights_0-1606835439929.png





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Muchas gracias v. Funciona. Funciona bien. ¡Funciona muy bien! FUNCIONA!!! 🤣Screenshot 2020-12-04 081431.png

Por favor acepte mis disculpas por el retraso en responder. El diseño de PowerApps no es mi trabajo de tiempo completo. Pero este proyecto es algo que tengo que hacer que pueda continuar.

DataInsights
Super User
Super User

@MYDATASTORY, pruebe esta medida:

Time Diff = 
SUMX ( TestData, TestData[End Time] - TestData[Start Time] )

DataInsights_0-1601656980364.png

DataInsights_1-1601657011072.png

DataInsights_2-1601657026994.png





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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