Forum Discussion
RunningTotal con Userelationship
Hola
Tengo una tabla con HireDate y TerminationDate y ambas fechas tienen una relación no activa con DateTable. Una relación activa no es posible.
Me gustaría crear un total acumulado de empleados empleados durante este período de tiempo.
Ejemplo: El empleado 1 comenzó el 1 de enero de 2020 y dejó la empresa el 30 de septiembre de 2022. Me gustaría tener un total acumulado entre esas fechas. En este caso será siempre 1, pero cumple mi propósito de rellenar un visual en todas las jerarquías de datos. Similar a la siguiente, pero también integrando la TerminationDate como la fecha final
Employed Duration =
VAR MaxDate = Max('DIM Date'[Date])
Return
Calculate(
[Emploeyee],
USERELATIONSHIP('Employee'[HireDate], 'DIM Date'[Date]), 'DIM Date'[Date] <= MaxDate,
ALL('DIM Date'))
Gracias
Tengo una solución más limpia para mi pregunta. El tiempo de carga también es más rápido
Employee Running Total = VAR StartDate = CALCULATE ( 'Employee Measures'[Employees], USERELATIONSHIP ( 'DIM Employee'[StartDate], 'DIM Date'[Date] ), FILTER ( ALL ( 'DIM Date' ), 'DIM Date'[Date] <= MAX ( 'DIM Date'[Date] ) ) ) VAR Terms = CALCULATE ( 'Employee Measures'[Employees], USERELATIONSHIP ( 'DIM Employee'[TermHelp], 'DIM Date'[Date] ), FILTER ( ALL ( 'DIM Date'[Date] ), 'DIM Date'[Date] <= MAX ( 'DIM Date'[Date] ) ), 'DIM Employee'[TermHelp] ) RETURN IF (StartDate - Terms = 0, Blank(), StartDate - Terms)
3 Replies
- Syndicate_AdminAdministrator
He obtenido el resultado que quería con el siguiente cálculo, pero funciona bastante mal.
Test = VAR TermDate = CALCULATE(MAX('DIM Employee'[TermHelp]), ALL('DIM Employee'), USERELATIONSHIP('DIM Employee'[TermHelp], 'DIM Date'[Date])) VAR SumTotal = IF(SELECTEDVALUE('DIM Date'[Date]) <= TermDate, CALCULATE([Employees], FILTER( ALL('DIM Date'), ISONORAFTER('DIM Date'[Date], MAX('DIM Date'[Date]), DESC)), USERELATIONSHIP('DIM Employee'[StartDate], 'DIM Date'[Date]))) VAR TermTotal = IF(SELECTEDVALUE('DIM Date'[Date]) <= TermDate, CALCULATE([Employees], FILTER( ALL('DIM Date'), ISONORAFTER('DIM Date'[Date], MAX('DIM Date'[Date]), DESC)), USERELATIONSHIP('DIM Employee'[TermHelp], 'DIM Date'[Date]))) RETURN SumTotal - TermTotalCualquier sugerencia de mejora del rendimiento sería muy apreciada.
- Syndicate_AdminAdministrator
Tengo una solución más limpia para mi pregunta. El tiempo de carga también es más rápido
Employee Running Total = VAR StartDate = CALCULATE ( 'Employee Measures'[Employees], USERELATIONSHIP ( 'DIM Employee'[StartDate], 'DIM Date'[Date] ), FILTER ( ALL ( 'DIM Date' ), 'DIM Date'[Date] <= MAX ( 'DIM Date'[Date] ) ) ) VAR Terms = CALCULATE ( 'Employee Measures'[Employees], USERELATIONSHIP ( 'DIM Employee'[TermHelp], 'DIM Date'[Date] ), FILTER ( ALL ( 'DIM Date'[Date] ), 'DIM Date'[Date] <= MAX ( 'DIM Date'[Date] ) ), 'DIM Employee'[TermHelp] ) RETURN IF (StartDate - Terms = 0, Blank(), StartDate - Terms)
- Syndicate_AdminAdministrator
No estoy seguro de si entiendo su requisito correctamente. Puede probar esta medida. Dado que no existe una relación activa entre dos tablas, puede usar una segmentación de datos o un filtro para filtrar el intervalo de fechas y comparar las fechas rangeStart/rangeEnd con HireDate/TermDate directamente.
Test = VAR rangeStart = MIN ( 'Dim Date'[Date] ) VAR rangeEnd = MAX ( 'Dim Date'[Date] ) RETURN CALCULATE ( [Employee], 'DIM Employee'[HireDate] <= rangeStart && 'DIM Employee'[TermDate] >= rangeEnd )Saludos
Equipo de Apoyo a la Comunidad _ Jing
Si esta publicación ayuda, por favor acéptela como Solución para ayudar a otros miembros a encontrarla. ¡Aprecio mucho tus Kudos!