Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!
¡Saludos a todos!
Tengo una mesa con esas características
Máquina | Hrs de producción | Culpa | Fecha |
A | 8 | 0 | 1/1/20 |
A | 5 | 0 | 2/1/20 |
A | 3 | 0 | 10/1/20 |
B | 4 | 0 | 15/1/20 |
A | 0 | 1 | 18/1/20 |
B | 8 | 0 | 23/1/20 |
A | 4 | 0 | 3/2/20 |
B | 8 | 0 | 6/2/20 |
B | 0 | 1 | 10/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 |
A | 8 | 0 | 1/1/20 | 8 |
A | 5 | 0 | 2/1/20 | 13 |
A | 3 | 0 | 10/1/20 | 16 |
B | 4 | 0 | 15/1/20 | 4 |
A | 0 | 1 | 18/1/20 | 16 |
B | 8 | 0 | 23/1/20 | 12 |
A | 4 | 0 | 3/2/20 | 4 |
B | 8 | 0 | 6/2/20 | 20 |
B | 0 | 1 | 10/2/2020 | 20 |
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?
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)