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
azimw
Regular Visitor

ayuda en Calcular duracion de horas trabajadas por dia

Hola, buen dia, quisiera que me ayuden en resolver un percanse que tengo, quiero calcular la duracion trabajada por cada item que tengo en la columna "numero". adjunto imagen

azimw_0-1658375579800.png

 

cabe mencionar que hay casos que iniciamos a las 23:00 H entonces quesiera que me calcule la duracion hasta las 00:00 "media noche" porque quiero la duracion por fecha. 

 

estoy empezando a usar powerbi, y quisiera de su ayuda para poder resorverlo.

 

gracias de antemano por su ayuda... 

 

Link del archivo 👉 https://drive.google.com/file/d/1inyAtaHcttZ5UVYdbEHq7k4oPOT8Iz0Z/view?usp=sharing  https://drive.google.com/file/d/1inyAtaHcttZ5UVYdbEHq7k4oPOT8Iz0Z/view?usp=sharing

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

Power BI has no concept of a row number, and your data is missing an index column.  At the very minimum you need to add that index column.

 

Your source data seems to have issues too, with multiple "Fin"  events per "Inicio"

 

lbendlin_0-1658454568852.png

Here is a general idea of how your measure could work, after you corrected the data quality issues.

worked = 
-- continuing?
var a = min('Reservorios Horas'[Index])
var b = CALCULATE(min('Reservorios Horas'[Tabla3.Status]),'Reservorios Horas'[Index]=a)
var c = if(b="Fin",CALCULATE(sum('Reservorios Horas'[Time]),'Reservorios Horas'[Index]=a),0)
-- full pairs
var d = filter('Reservorios Horas','Reservorios Horas'[Tabla3.Status]="Inicio")
var e = ADDCOLUMNS(d,"T",var i = [Index] return calculate(max('Reservorios Horas'[Time]),'Reservorios Horas'[Index]=i+1),
                     "D",var i = [Index] return calculate(max('Reservorios Horas'[Date]),'Reservorios Horas'[Index]=i+1))
var f = filter(e,[Date]=[D])
var f1 = sumx(f,[T]-[Time])
-- extending into the night?
var g = max('Reservorios Horas'[Index])
var h = CALCULATE(min('Reservorios Horas'[Tabla3.Status]),'Reservorios Horas'[Index]=g)
var j = if(h="Inicio",1-CALCULATE(sum('Reservorios Horas'[Time]),'Reservorios Horas'[Index]=g),0)
return 24*(c + f1 + j)

View solution in original post

1 REPLY 1
lbendlin
Super User
Super User

Power BI has no concept of a row number, and your data is missing an index column.  At the very minimum you need to add that index column.

 

Your source data seems to have issues too, with multiple "Fin"  events per "Inicio"

 

lbendlin_0-1658454568852.png

Here is a general idea of how your measure could work, after you corrected the data quality issues.

worked = 
-- continuing?
var a = min('Reservorios Horas'[Index])
var b = CALCULATE(min('Reservorios Horas'[Tabla3.Status]),'Reservorios Horas'[Index]=a)
var c = if(b="Fin",CALCULATE(sum('Reservorios Horas'[Time]),'Reservorios Horas'[Index]=a),0)
-- full pairs
var d = filter('Reservorios Horas','Reservorios Horas'[Tabla3.Status]="Inicio")
var e = ADDCOLUMNS(d,"T",var i = [Index] return calculate(max('Reservorios Horas'[Time]),'Reservorios Horas'[Index]=i+1),
                     "D",var i = [Index] return calculate(max('Reservorios Horas'[Date]),'Reservorios Horas'[Index]=i+1))
var f = filter(e,[Date]=[D])
var f1 = sumx(f,[T]-[Time])
-- extending into the night?
var g = max('Reservorios Horas'[Index])
var h = CALCULATE(min('Reservorios Horas'[Tabla3.Status]),'Reservorios Horas'[Index]=g)
var j = if(h="Inicio",1-CALCULATE(sum('Reservorios Horas'[Time]),'Reservorios Horas'[Index]=g),0)
return 24*(c + f1 + j)

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.

Top Solution Authors