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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
Anonymous
Not applicable

¿Suma acumulada por categoría, fecha y con un filtro de restablecimiento?

¡Saludos a todos!

Tengo una mesa con esas características

Máquina Hrs de producción Culpa Fecha
A801/1/20
A502/1/20
A3010/1/20
B4015/1/20
A0118/1/20
B8023/1/20
A403/2/20
B806/2/20
B0110/2/2020

Y yo haría una nueva columna acumulativa que suma las horas de producción por fecha y categoría, y restablecer cuando la columna Error es 1, como sigue:

Máquina Hrs de producción Culpa Fecha Hrs acumulativos
A801/1/208
A502/1/2013
A3010/1/2016
B4015/1/204
A0118/1/2016
B8023/1/2012
A403/2/204
B806/2/2020
B0110/2/202020

Encontré cómo acumular por fecha y categorías, pero no el caso de reset con un valor, encontré sólo con el período!

¿Alguna idea?

1 REPLY 1
d_gosbell
Super User
Super User

Así que podría crear una columna calculada con una expresión como la siguiente

Cummulative Hrs = 
// get the date for the current row
VAR maxDate = 'Table'[Date]
// get the minimum date for the table
VAR minDate = MINX(ALL('Table'[Date]), 'Table'[Date])
// get the current machine
VAR machine = 'Table'[Machine]
// find the previous fault date
VAR minFaultDate = CALCULATE(MAX('Table'[Date]),ALL('Table'), 'Table'[Date] < maxDate , 'Table'[Fault] = 1, 'Table'[Machine] = machine )
// either use the previous fault date or the min date in the table as the starting point for the cummulative sum
var fromDate = COALESCE(minFaultDate, minDate)
// sum the hours between the fromDate and maxDate for the current machine
RETURN CALCULATE(sum('Table'[Production Hrs]), ALL('Table'), 'Table'[Date] >= fromDate, 'Table'[Date] <= maxDate, 'Table'[Machine] = machine)

Tenga en cuenta que esta columna calc hace uso de CALCULATE y normalmente intento evitar que en columnas calc, ya que provoca una transición de contexto y puede causar problemas si intenta crear más de una columna calculada que utiliza CALCULATE.

Por lo tanto, podría realizar un cálculo similar a una medida (que se calcula en tiempo de ejecución y no se almacena como una columna)

Cummulative Hrs (Measure) = 
// get the date for the current row
VAR maxDate = MAX('Table'[Date])
// get the minimum date for the table
VAR minDate = CALCULATE(MIN('Table'[Date]), all('Table'[Date]))
// get the current machine
VAR machine = SELECTEDVALUE('Table'[Machine])
// find the previous fault date
VAR minFaultDate = CALCULATE(MAX('Table'[Date]),ALL('Table'), 'Table'[Date] < maxDate , 'Table'[Fault] = 1, 'Table'[Machine] = machine )
// either use the previous fault date or the min date in the table as the starting point for the cummulative sum
var fromDate = COALESCE(minFaultDate, minDate)
// sum the hours between the fromDate and maxDate for the current machine
RETURN CALCULATE(sum('Table'[Production Hrs]), ALL('Table'), 'Table'[Date] >= fromDate, 'Table'[Date] <= maxDate, 'Table'[Machine] = machine)

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors